> Hello R-users
> The help I received from Petr helped me created this solution to my problems.
>
> t1<-with(mydata ,aggregate(mydata$Y,
> list(mydata$time,mydata$treatment, mydata$expREP, mydata$techREP) ,
> median, na.rm=T)) ### find median by factors ####
>
> colnames(t1)<-c("time","treatment","expREP","techREP","Y50") ### column name
> ##
>
> newdata<-merge(mydata, t1, by.x= names(mydata)[2:5],
> by.y=names(t1)[1:4], all=T)
>
Another way is to use the reshape package, http://had.co.nz/reshape
library(reshape)
molten <- melt(mydata, m="log2Abun")
cast(molten, time + treatment + expREP + techREP ~ ., median)
# You can also create many other "shapes" easily:
cast(molten, expREP + techREP ~ time + treatment , median)
cast(molten, expREP + techREP ~ time + treatment , median, margins=TRUE)
Hadley
______________________________________________
[email protected] 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.