I have these vectors:
texts=c("AANAAA","NNAAAA","AAAAAA", "NAAANN")
letter=c("C","C","G","T","P","D")
I am trying to replace N for each element in texts and replace it with a character from second array letter by position.
Take "AANAAA", the N at third position should be replaced by the third element of letter, i.e. G
My expected output is:
texts=c("AAGAAA","CCAAAA","AAAAAA", "CAAAPD")
I was trying gsub and a for loop
for (i in 1:6) {
for (j in 1:4)
gsub("N",letter[i],texts[j][i])
}
but it didn't work.