Re: [R] Decomposing a List

2013-04-26 Thread William Dunlap
tware wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Bert Gunter > Sent: Thursday, April 25, 2013 7:54 AM > To: ted.hard...@wlandres.net > Cc: R mailing list > Subject: Re: [R] Dec

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

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) >

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 <- strsplit(paste(sample(LETTERS,1e6,rep=TRUE),sample(1:10,1

Re: [R] Decomposing a List

2013-04-25 Thread arun
ary(stringr)  word(sapply(L,paste,collapse=" "),1) #[1] "A1" "A2" "A3" A.K. - Original Message - From: "ted.hard...@wlandres.net" To: r-help@r-project.org Cc: Sent: Thursday, April 25, 2013 6:16 AM Subject: [R] Decomposing a List Greetings!

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 Hard

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 wrote: > 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

[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] =