Re: [R] Selecting first 7 elements

2010-05-30 Thread David Winsemius
On May 29, 2010, at 11:37 PM, Kang Min wrote: What if I want to select the 8th to 14th element of the list? I tried to use [ again, but it doesn't work. x[8:14] (And I could not get Iverson's earlier method to work properly on a long list. It just returned the whole list. Did it work

Re: [R] Selecting first 7 elements

2010-05-30 Thread Kang Min
Hmm x[8:14] didn't work. Yes Iverson's method worked, I wanted the whole list, with 7 elements in each vector. Now I want the whole list as well, but with the 8th to 14th element. On May 30, 7:47 pm, David Winsemius dwinsem...@comcast.net wrote: On May 29, 2010, at 11:37 PM, Kang Min wrote:

Re: [R] Selecting first 7 elements

2010-05-30 Thread David Winsemius
On May 30, 2010, at 9:44 AM, Kang Min wrote: Hmm x[8:14] didn't work. Yes Iverson's method worked, I wanted the whole list, with 7 elements in each vector. Now I want the whole list as well, but with the 8th to 14th element. Oh, ... then in what sense did the lapply method not work? What

Re: [R] Selecting first 7 elements

2010-05-30 Thread Jorge Ivan Velez
Hi Kang, Try either lapply(x, [, 8:14) # Erik Iverson's method or lapply(x, function(x) x[8:14]) HTH, Jorge On Sun, May 30, 2010 at 9:44 AM, Kang Min wrote: Hmm x[8:14] didn't work. Yes Iverson's method worked, I wanted the whole list, with 7 elements in each vector. Now I want the

Re: [R] Selecting first 7 elements

2010-05-30 Thread Kang Min
Sorry I made a mistake in my code, lapply(x, [, 8:14) works fine now. Thanks. On May 30, 10:55 pm, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: HiKang, Try either lapply(x, [, 8:14)   # Erik Iverson's method or lapply(x, function(x) x[8:14]) HTH, Jorge On Sun, May 30, 2010

Re: [R] Selecting first 7 elements

2010-05-29 Thread Kang Min
What if I want to select the 8th to 14th element of the list? I tried to use [ again, but it doesn't work. [ is a function, and you want to use it on each element of the list, so... lapply(x, [, c(1:7)) and the call to c() is of course not necessary, since : will generate a

[R] Selecting first 7 elements

2010-05-23 Thread Kang Min
Hi, I have a list of 100, each list has 20 elements, and I would like to select the first 7 elements in each list. Let's take the alphabet as an example. x - lapply(1:100, function(i) sample(LETTERS)) I tried x[[1:7]], but it doesn't work. Can anyone enlighten me on how to do such selections?

Re: [R] Selecting first 7 elements

2010-05-23 Thread Erik Iverson
Kang Min wrote: Hi, I have a list of 100, each list has 20 elements, and I would like to select the first 7 elements in each list. Let's take the alphabet as an example. x - lapply(1:100, function(i) sample(LETTERS)) I tried x[[1:7]], but it doesn't work. Can anyone enlighten me on how to do

Re: [R] Selecting first 7 elements

2010-05-23 Thread Erik Iverson
[ is a function, and you want to use it on each element of the list, so... lapply(x, [, c(1:7)) and the call to c() is of course not necessary, since : will generate a vector. __ R-help@r-project.org mailing list

Re: [R] Selecting first 7 elements

2010-05-23 Thread Kang Min
Thanks a lot, it works! On May 23, 3:10 pm, Erik Iverson er...@ccbr.umn.edu wrote: [ is a function, and you want to use it on each element of the list, so... lapply(x, [, c(1:7)) and the call to c() is of course not necessary, since : will generate a vector.