I am a big believer in reformatting the data so that it is "long." The usefulness of a long format is especially evident when it comes to such problems. Fortunately, it is easy enough to remake such data in almost any format with the reshape package.
If I understood your question correctly, you need to have a Memory and Naive value for each line. For some reason, we need to make the column names unique to reshape::melt() .
colnames(df) <- paste(colnames(df), 1:ncol(df), sep = "_")
Then you need to create an ID column. You can either do
df$ID <- 1:nrow(df)
or, if these growth names are significant
df$ID <- rownames(df)
Now, with the reshape package
library(reshape) df.m <- melt(df, id = "ID") df.m <- cbind(df.m, colsplit(df.m$variable, split = "_", names = c("Measure", "N"))) df.agg <- cast(df.m, ID ~ Measure, fun = mean)
df.agg should now look like your desired output snippet.
Or, if you only need common tools across all lines, the Zack suggestion will work. Something like
m <- colMeans(df) tapply(m, colnames(df), mean)
You can get the same result, but formatted as a dataframe with
cast(df.m, .~variable, fun = mean)