[R] R Help-how to use sapply w/tapply

arun smartpink111 at yahoo.com
Mon Oct 14 21:40:54 CEST 2013


(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))

res2 <-  aggregate(.~Genotype, data=Gene,mean)

 res3 <- ddply(Gene,.(Genotype),numcolwise(mean))

#[1] TRUE

resNew <- data.frame(Genotype=rownames(res),res,stringsAsFactors=FALSE)
 attr(resNew,"row.names") <- attr(res2,"row.names")
#[1] TRUE


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