Displaying 1 result from an estimated 1 matches for "mylast".
2007 Apr 09
3
do.call vs. lapply for lists
...fic terminology. I would appreciate it if
you could take a moment to enlighten me.
Thanks,
Bob
mydata <- data.frame(
id = c('001','001','001','002','003','003'),
math = c(80,75,70,65,65,70),
reading = c(65,70,88,NA,90,NA)
)
mydata
mylast <- lapply( split(mydata,mydata$id), tail, n=1)
mylast
class(mylast) #It's a list, so lapply will so *something* with it.
#This gets the desired result:
do.call("rbind", mylast)
#This doesn't do the same thing, which confuses me:
lapply(mylast,rbind)
#...and data.frame won...