Hi Chris, Try ?ave will help you. Anyway, I guess you are computing a statistic.
strs <- " level.1 level.2 observation 1 1 0.5 1 1 0.2 1 2 0.6 1 2 0.4 2 3 0.8 2 3 0.7 2 4 0.6 2 4 0.4 " df <- read.table(textConnection(strs),header=T) df$mean1 <- ave(df$observation, df$level.1, FUN = function(x) mean(x)) df$mean2 <- ave(df$observation, df$level.2, FUN = function(x) mean(x)) df.mean <- merge(unique(df[,c(1,4)]),unique(df[,c(2,5)]),by.x = "level.1", by.y = "level.2") df.mean$square <- (df.mean$mean1 - df.mean$mean2)^2 Regards, Wu ----- A R learner. -- View this message in context: http://r.789695.n4.nabble.com/functions-and-multiple-levels-tp2329935p2330001.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.