[R] extraction of vector elements to new list

Patrick Zimmermann brassnotdead at googlemail.com
Mon Jul 23 15:59:46 CEST 2007

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


# is [1] "f" "g"

# I thought


# 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?


More information about the R-help mailing list