Skip to content
Prev 157448 / 398506 Next

using tapply on a data frame in a function

eric lee <ericlee100 <at> gmail.com> writes:
Thanks for the self-running example! Not really a function problem, though.

d <- data.frame(cbind(cluster=1:2, value1=1:10, value2=11:20))
d

FindClusterTraits <- function(framename, index){
  tapply(framename[[index]], framename[["cluster"]], mean)
}

FindClusterTraits(d, 'value1')

Note that the return(MeanCluster) is not required in R.

Dieter