我一直停留在此错误上,在该错误中,我要发送要分组的列名,要汇总的列名以及将这些结果放置到执行此操作的函数的新列名。但是我一直在收到此错误,而不是查看特定条件,而是将整个列加起来,但是如果我将colName1更改为实际的列名,它将正常工作。
我的代码如下:
results <- MACO
DANG <- function(dF, colGroupName1, colName1, newColName){
dF %>%
group_by_(colGroupName1) %>%
mutate(!!newColName := sum(dF[[colName1]]))
}
results <- DANG(results,"Open.Geo","ACT.Volume","Sum.Criteria")
In this picture my code gives me the left results (incorrect) but I need to get the right results:
我一直在阅读有关报价的所有内容,但不确定如何处理这种情况。 谢谢。
答案 0 :(得分:0)
我们需要group_by_at
,它可以将字符串作为输入。同样,可以使用sym
将'colName1'转换为符号,然后求值(!!
)
DANG <- function(dF, colGroupName1, colName1, newColName){
dF %>%
group_by_at(vars(colGroupName1)) %>%
mutate(!!newColName := sum(!! rlang::sym(colName1)))
}
results <- DANG(results, "Open.Geo", "ACT.Volume", "Sum.Criteria")