R:new_quosure(NextMethod())中出错:找不到函数;新的“问题”;
考虑一个数据帧:R:new_quosure(NextMethod())中出错:找不到函数;新的“问题”;,r,group-by,dplyr,quosure,R,Group By,Dplyr,Quosure,考虑一个数据帧: 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", "Tues
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))
我试着分组并总结,但是,我不断得到错误
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))
)
group-by_u
功能已被弃用,当前的tidyeval方法是将字符向量转换为符号,然后将其解压缩到group-by
:
library(dplyr)
data %>%
group_by(!!!syms(model.data.dim.names)) %>%
summarise(
mean_adj1 = mean(out, na.rm=FALSE),
mean_adj2 = mean(out) / mean(rate)
)
## A tibble: 6 x 5
## Groups: a, b [4]
# a b c mean_adj1 mean_adj2
# <dbl> <fct> <dbl> <dbl> <dbl>
#1 1 apples 12 12 1200
#2 1 apples 22 16 533.
#3 1 oranges 22 14 700
#4 2 apples 45 18 450
#5 2 apples 67 20 286.
#6 3 grapefruit 28 22 367.
库(dplyr)
数据%>%
分组依据(!!!syms(model.data.dim.names))%>%
总结(
平均值=平均值(out,na.rm=FALSE),
平均值2=平均值(超出)/平均值(比率)
)
##一个tibble:6x5
##组:a、b[4]
#a b c平均值
#
#1苹果12 12 1200
#苹果2216533。
#3 1橙子2214700
#4 2个苹果45 18 450
#5 2个苹果67 20 286。
#6 3葡萄柚28 22 367。
我们可以使用dplyr
中的groupby\u at
,它可以将字符串作为输入
library(dplyr)
data %>%
group_by_at(model.data.dim.names) %>%
summarise(
mean_adj1 = mean(out, na.rm=FALSE),
mean_adj2 = mean(out) / mean(rate)
)
# A tibble: 6 x 5
# Groups: a, b [4]
# a b c mean_adj1 mean_adj2
# <dbl> <fct> <dbl> <dbl> <dbl>
#1 1 apples 12 12 1200
#2 1 apples 22 16 533.
#3 1 oranges 22 14 700
#4 2 apples 45 18 450
#5 2 apples 67 20 286.
#6 3 grapefruit 28 22 367.
库(dplyr)
数据%>%
分组依据(model.data.dim.names)%>%
总结(
平均值=平均值(out,na.rm=FALSE),
平均值2=平均值(超出)/平均值(比率)
)
#一个tibble:6x5
#组:a、b[4]
#a b c平均值
#
#1苹果12 12 1200
#苹果2216533。
#3 1橙子2214700
#4 2个苹果45 18 450
#5 2个苹果67 20 286。
#6 3葡萄柚28 22 367。
两周前运行正常的代码也出现了同样的错误。应用dplyr::group_by()
时发生。我有dplyr包版本0.7.6,并将其更新为0.8.0.1。这就解决了问题。您可能有一个过时的dplyr
包(它不同于plyr
)和一个更新的rlang
包(或者visa反之亦然)。您可以显示来自sessionInfo()
的软件包版本信息吗?它给出了相同的错误:“new_-quosures中的错误(NextMethod()):找不到函数“new_-quosures”。请确保您有最新版本的dplyr,并且rlangIt给出了相同的错误:“new_-quosures中的错误(NextMethod()):找不到函数”new_-quosures“@BruceWayne您的dplyr
版本是什么?我有packageVersion('dplyr')#[1]“0.8.0.1”
group\u by\u at
是一个新版本function@BruceWayne不确定这个问题。它对metidyr library工作正常。它会把事情搞砸。删除tidyr会有帮助
library(dplyr)
data %>%
group_by_at(model.data.dim.names) %>%
summarise(
mean_adj1 = mean(out, na.rm=FALSE),
mean_adj2 = mean(out) / mean(rate)
)
# A tibble: 6 x 5
# Groups: a, b [4]
# a b c mean_adj1 mean_adj2
# <dbl> <fct> <dbl> <dbl> <dbl>
#1 1 apples 12 12 1200
#2 1 apples 22 16 533.
#3 1 oranges 22 14 700
#4 2 apples 45 18 450
#5 2 apples 67 20 286.
#6 3 grapefruit 28 22 367.