Re: [R] Decomposing a List

2013-04-26 Thread William Dunlap
Of Bert Gunter Sent: Thursday, April 25, 2013 7:54 AM To: ted.hard...@wlandres.net Cc: R mailing list Subject: Re: [R] Decomposing a List Well, what you really want to do is convert the list to a matrix, and it can be done directly and considerably faster than with the (implicit) looping

[R] Decomposing a List

2013-04-25 Thread Ted Harding
Greetings! For some reason I am not managing to work out how to do this (in principle) simple task! As a result of applying strsplit() to a vector of character strings, I have a long list L (N elements), where each element is a vector of two character strings, like: L[1] = c(A1,B1) L[2] =

Re: [R] Decomposing a List

2013-04-25 Thread Jorge I Velez
Dear Dr. Harding, Try sapply(L, [, 1) sapply(L, [, 2) HTH, Jorge.- On Thu, Apr 25, 2013 at 8:16 PM, Ted Harding ted.hard...@wlandres.netwrote: Greetings! For some reason I am not managing to work out how to do this (in principle) simple task! As a result of applying strsplit() to a

Re: [R] Decomposing a List

2013-04-25 Thread Ted Harding
Thanks, Jorge, that seems to work beautifully! (Now to try to understand why ... but that's for later). Ted. On 25-Apr-2013 10:21:29 Jorge I Velez wrote: Dear Dr. Harding, Try sapply(L, [, 1) sapply(L, [, 2) HTH, Jorge.- On Thu, Apr 25, 2013 at 8:16 PM, Ted Harding

Re: [R] Decomposing a List

2013-04-25 Thread arun
To: r-help@r-project.org Cc: Sent: Thursday, April 25, 2013 6:16 AM Subject: [R] Decomposing a List Greetings! For some reason I am not managing to work out how to do this (in principle) simple task! As a result of applying strsplit() to a vector of character strings, I have a long list L (N

Re: [R] Decomposing a List

2013-04-25 Thread Bert Gunter
Well, what you really want to do is convert the list to a matrix, and it can be done directly and considerably faster than with the (implicit) looping of sapply: f1 - function(l)sapply(l,[,1) f2 - function(l)matrix(unlist(l),nr=2) l -

Re: [R] Decomposing a List

2013-04-25 Thread David Winsemius
On Apr 25, 2013, at 7:53 AM, Bert Gunter wrote: Well, what you really want to do is convert the list to a matrix, and it can be done directly and considerably faster than with the (implicit) looping of sapply: f1 - function(l)sapply(l,[,1) f2 - function(l)matrix(unlist(l),nr=2) l -

Re: [R] Decomposing a List

2013-04-25 Thread Bert Gunter
Well... WIth the same list,l,as before: system.time(x3 - simplify2array(l)) user system elapsed 2.110.052.20 system.time(x2 - f2(l)) ## the matrix(unlist(...)) one user system elapsed 0.110.000.11 identical(x2,x3) [1] TRUE So kind of a big difference if you