Sending in Column Name to ddply from Function

plyr, r

Solution

There has got to be a better way. And I couldn't figure out how to make it work with summarise.

my.fun <- function(df, count.column) { 
  ddply(df, .(x), function(d) sum(d[[count.column]]))
}

dat <- data.frame(x=letters[1:2], y=1:10)

> my.fun(dat, 'y')
  x V1
1 a 25
2 b 30
> 

Problem

I'd like to be able to send in a column name to a call that I am making to `ddply`. An example `ddply` call: ``` ddply(myData, .(MyGrouping), summarise, count=sum(myColumnName)) ``` If I have `ddply` wrapped within another function is it possible to wrap this so that I can pass in an arbitrary value as `myColumnName` to the calling function?

Original source