How do I access a position in a vector of characters?

2

The following code returns a vector of 12 letters:

> res <- "ACDEDEAEDCED"
> res <- strsplit(res,"", FALSE)
> View(res[4])
Error in .subset2(x, i, exact = exact) : índice fora de limites

More when I try to access a position and specify it gives error. I've tried it in many ways. Among them res [1,4], res [ 4] ....

    
asked by anonymous 07.03.2016 / 00:07

1 answer

2

The function strsplit returns a list, so the res vector is a list, see:

res <- "ACDEDEAEDCED"
res <- strsplit(res,"", FALSE)
res
[[1]]
 [1] "A" "C" "D" "E" "D" "E" "A" "E" "D" "C" "E" "D"

If you want element 4 of the first element of the list, you can pick it up as follows:

res[[1]][4]
[1] "E"
    
07.03.2016 / 00:21