[R] R Help-how to use sapply w/tapply
arun
smartpink111 at yahoo.com
Mon Oct 14 21:40:54 CEST 2013
Hi,
(Please use ?dput() to share the example dataset. Avoid using images to show dataset. Also, please read the posting guide esp. regarding home work, assignments etc.)
res <- sapply(Gene[,-1],function(x) tapply(x,list(Gene$Genotype),mean))
#or
res2 <- aggregate(.~Genotype, data=Gene,mean)
#or
library(plyr)
res3 <- ddply(Gene,.(Genotype),numcolwise(mean))
identical(res2,res3)
#[1] TRUE
resNew <- data.frame(Genotype=rownames(res),res,stringsAsFactors=FALSE)
attr(resNew,"row.names") <- attr(res2,"row.names")
identical(resNew,res2)
#[1] TRUE
A.K.
So I'm having a problem with the part b of the assignment.
This is the question
This is how I solved
Part A
now for
Part B
Am i supposed to do something along the lines of
sapply(tapply(Gene[ , ], Gene$Genotype), mean)
This doesn't work.
More information about the R-help
mailing list