Dear R-community,

I have got a list of vectors and would like to extract the first two
elements of each vector to a new list.

My list is of the style:

my.list = list(c("a", "b", "c"), c("d", "e"), c("f", "g", "h", "i"), ...)

#I want:

new.list = list(c("a", "b"), c("d", "e"), c("f", "g"), ...)

# As

my.list[[3]][1:2]

# is [1] "f" "g"

# I thought

my.list[[1:3]][1:2]

# would be

# [[1]]
# [1] "a" "b"

# [[2]]
# [1] "d" "d"

# [[3]]
# [1] "f" "g"

# but is: 'Error: recursive indexing failed at level 2'


I think it should be easy, but none of my tried combinations of '['
and 'c(' worked.
Who can help?

Patrick

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to