error recorer string with for in r

1

I want to go through a text string using a loop, but when I run the code, it only makes the first iteration.

text <- "CTGGTGCTCGTAGACCGCAGAACC";
i=0
i1=i+3
for (i in 1:length(text)){
 DNA <-substr(text,i,i1)
 i=i1+1
 i1=i+2
 print(DNA)
}

What is the error?

    
asked by francesc 27.10.2017 в 10:26
source

1 answer

3

To get the length of a text type variable use nchar :

for (i in 1:nchar(text))

Length() is used for vectors, factors and objects. Documentation

    
answered by 27.10.2017 / 10:32
source