Magnus <account <at> zulutime.net> writes: > > I have a simulation program that generates a data frame for each run. I > aggregate the data.frames into a list (df.list). The structure of all data > frames is the same, only the values are different. > > I then want to aggregate the various runs. Currently I use the following > method (for three runs): > > means = (df.list[[1]]$variable + df.list[[2]]$variable + > df.list[[3]]$variable)/3 > > I would like to do this in a more parsimonious way, for example using lapply > or related commands, but I can't seem to figure out the magic touch. Any > thoughts on the best way to accomplish this? >
x <- sapply(df.list,"[[","variable") will extract the variables as a matrix. If the variables are all vectors of the same length then you might follow this with rowSums(x)/ncol(x) or apply(x,1,mean) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.