Thanks, in a way this has worked... with a slight modification to this: narrow3<-aggregate(narrow2$value~narrow2$gene+narrow2$gender,data=narrow2,mean) narrow4<-aggregate(narrow2$value~narrow2$gene+narrow2$gender,data=narrow2,sd)
which gives a table of the 24000 gene&gender means (narrow3) and the standard deviations (narrow4) which I then merge in to one df using narrow5<-merge(narrow3,narrow4,by=c("narrow2$gene","narrow2$gender")) colnames(narrow5)<-c("gene","gender","mean","sd") Is there a way I can lift the mean and std.dev. values from data frame narrow5 and paste them to the original narrow2 df? In effect... R would read what gene and gender each row of narrow2 has & then paste in the according mean value in to a new column. then do the same for a new sd column. each mean/sd value would occur in the new column 80 times (there are 80 occurrences of each gene&gender combination). rob -- View this message in context: http://r.789695.n4.nabble.com/Mean-of-matched-data-tp4636856p4636871.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.