ddply + summarise function column name input

折月煮酒 提交于 2019-11-30 23:15:39

Although this is probably not the intended usage for summarize and there must be much better approaches to your problem, the direct answer to your question is to use get:

ddply(t.df.l, c("day","variable"), summarise, cor(get(colnames(t.df)[2]), value))

Edit: here is for example one approach that is in my opinion better suited to your problem:

ddply(t.df.l, c("day", "variable"), function(x)cor(x["X1"], x["value"]))

Above, "X1" can be also replaced by 2 or the name of a variable holding "X1", etc. It depends how you want to programmatically access the column.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!