Re: [R] paste together object names to pass it on to a function

2009-02-02 Thread stefan.d...@gmail.com
Hello y'll, thanks a lot for your hints. The easiest solution was the one from Jim, using "[[" whose true function I did not realize fully. About apply and the sorts: I agree that if you get them to work the are much faster and yield nice, compact code. But I have never fully understood the inner

Re: [R] paste together object names to pass it on to a function

2009-01-30 Thread David Winsemius
Perhaps this will help: #Data Example gnuff<-list() gnuff$IHD$LE<-66 gnuff$LUNG$LE <-55 #This is the list, where I collect data for different diseases at the #second level of the list #Now I want to do calcualtions just for these two diseases and the #sub-list "LE" within these diseases nam <-

Re: [R] paste together object names to pass it on to a function

2009-01-30 Thread Gabor Grothendieck
Or perhaps: lapply(gnuff, "[[", "LE") On Fri, Jan 30, 2009 at 12:35 PM, Patrick Burns wrote: > A rule of thumb is that if the solution seems a lot > harder than the task, there is probably a better > approach. I think you want something like: > > lapply(gnuff[nam], function(x) x$LE) > > > Patr

Re: [R] paste together object names to pass it on to a function

2009-01-30 Thread Patrick Burns
A rule of thumb is that if the solution seems a lot harder than the task, there is probably a better approach. I think you want something like: lapply(gnuff[nam], function(x) x$LE) Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "

Re: [R] paste together object names to pass it on to a function

2009-01-30 Thread jim holtman
This should do it: ?"[[" > gnuff<-list() > gnuff$IHD$LE<-66 > gnuff$LUNG$LE <-55 > > > > nam <- c("LUNG","IHD") > > x <- numeric(2) # allocate > for(i in 1:2) + x[i] <- gnuff[[nam[i]]]$LE / 2 > > x [1] 27.5 33.0 On Fri, Jan 30, 2009 at 12:06 PM, stefan.d...@gmail.com wrote: > Hello, > I have