plyr の結果の列名に変数の値を割り当てる方法はありますか? したがって、このコードでは...
column_name <- 'total'
df <- data.frame(a=c('a','b'), b=c(1,2))
ddply(df, .(a), summarise, column_name=sum(b))
As you know, this spits out a data frame which consists of variables a
and column_name
. However, what I want to get it is variables a
and total
, where total
is assigned dynamically by a variable's value, since actually, I want to process it inside a loop, that I can't specify it directly inside ddply function.
For you information, this code doesn't work.
ddply(df, .(a), summarise, get(column_name)=sum(b))
So is there any solution to deal with it?