考虑一个数据框:
data = data.frame(a=c(1,1,1,2,2,3),
b=c("apples", "oranges", "apples", "apples", "apples", "grapefruit"),
c=c(12, 22, 22, 45, 67, 28),
d=c("Monday", "Monday", "Monday", "Tuesday", "Wednesday", "Tuesday"),
out = c(12, 14, 16, 18, 20, 22),
rate = c(0.01, 0.02, 0.03, 0.04, 0.07, 0.06))
我正在尝试 group_by 并进行总结,但是我不断收到错误消息
Error in new_quosures(NextMethod()) :
could not find function "new_quosures"
我正在使用的代码如下:
model.data.dim.names <- c("a", "b", "c")
data2 <- data %>% group_by_(.dots = model.data.dim.names) %>% summarise(
mean_adj1 = (mean(out, na.rm=FALSE)),
mean_adj2 = (mean(out)/mean(rate))
)
请注意,这是虚拟数据,错误会在带有虚拟数据的 Windows 操作系统中重现。此外,我正在使用 Windows 操作系统。此外,我尝试了以下方法:
- 删除 plyr
- 检查和编辑 NA/无限值
- 将数据框转为数据表并运行代码
您能否帮助我了解错误的根本原因或我可以使用的替代方法?
Answer:
1) tidyr library screws up with it. Removing tidyr helps
2) use most updated dplyr library and group_by/ group_by_at/group_by(!!!syms(model.data.dim.names) works