When I have a vector of vectors in R, how do I select a vector that contains one element from each outer vector?
For example, given this data:
> data<-c("1,2","3,4","5,6")
> data<-strsplit(data,",")
> data
[[1]]
[1] "1" "2"
[[2]]
[1] "3" "4"
[[3]]
[1] "5" "6"
How do I get a vector containing (1,3,5) and nothing else?
Thanks!
Since your example uses
strsplitI assume this is how you obtain your dataset in the first place? If so, using regular expressions also work and might be slightly faster. e.g.