[R] average columns of data frame corresponding to replicates
Juliet Hannah
juliet.hannah at gmail.com
Tue Sep 7 18:00:55 CEST 2010
Hi Group,
I have a data frame below. Within this data frame there are samples
(columns) that are measured more than once. Samples are indicated by
"idx". So "id1" is present in columns 1, 3, and 5. Not every id is
repeated. I would like to create a new data frame so that the repeated
ids are averaged. For example, in the new data frame, columns 1, 3,
and 5 of the original will be replaced by 1 new column that is the
mean of these three. Thanks for any suggestions.
Juliet
myData <- data.frame("sample1.id1" =rep(1,10),
"sample1.id2"=rep(2,10),
"sample2.id1" = rep(2,10),
"sample1.id3" = 1:10,
"sample3.id1" = rep(1,10),
"sample1.id4" = 1:10,
"sample2.id2" = rep(1,10))
repeat_ids <- c("id1","id2")
More information about the R-help
mailing list