Hi R-users I have a list with 19 elments. This elements are a new list of 2 elements, for example: times<- [[1]] [[1]]$time 11 10 147 206 30 [[1]]$n [1] 3 ....... [[19]] [[19]]$time 96 96 96 94 98 78 78 78 147 100 4 [[19]]$n [1] 6 Does anyone know how obtain a vector with the elements $time as quick as possible (no loops)? Thank you Juan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 17 Jun 2002, Juan Ramon Gonzalez wrote:> Hi R-users > > I have a list with 19 elments. This elements are a new list of 2 elements, > for example: > > times<- > [[1]] > [[1]]$time > 11 10 > 147 206 30 > > [[1]]$n > [1] 3 > > ....... > > [[19]] > [[19]]$time > 96 96 96 94 98 > 78 78 78 147 100 4 > > [[19]]$n > [1] 6 > > Does anyone know how obtain a vector with the elements $time as quick as > possible (no loops)? >assuming you want them all concatenated unlist(lapply(times, function(x) x$time)) If you have lots of short lists like this one it may not be much faster than a loop, but with long lists it should be. -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Juan Ramon Gonzalez wrote:> > Hi R-users > > I have a list with 19 elments. This elements are a new list of 2 elements, > for example: > > times<- > [[1]] > [[1]]$time > 11 10 > 147 206 30 > > [[1]]$n > [1] 3 > > ....... > > [[19]] > [[19]]$time > 96 96 96 94 98 > 78 78 78 147 100 4 > > [[19]]$n > [1] 6 > > Does anyone know how obtain a vector with the elements $time as quick as > possible (no loops)?lapply(times, function(x) x$time) or unlist(lapply(times, function(x) x$time)) to get only one vector Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 17:01 17/06/02 +0200, you wrote:>Hi R-users > >I have a list with 19 elments. This elements are a new list of 2 elements, >for example: > >times<- >[[1]] >[[1]]$time > 11 10 >147 206 30 > >[[1]]$n >[1] 3 > >....... > >[[19]] >[[19]]$time > 96 96 96 94 98 > 78 78 78 147 100 4 > >[[19]]$n >[1] 6 > >Does anyone know how obtain a vector with the elements $time as quick as >possible (no loops)?Giving your example, this should work: unlist(lapply(times, "[[", 1)) EP>Thank you > > >Juan > > > > > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.->r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html >Send "info", "help", or "[un]subscribe" >(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._> >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._