gpt4 book ai didi

r - Gather_ 不起作用。在标准评估模式下引用和〜ing不应该具有相同的效果吗?

转载 作者:行者123 更新时间:2023-12-02 02:52:39 24 4
gpt4 key购买 nike

我在让 tidyr 的 Gather 在其标准评估版本 Gather_ 中工作时遇到问题:

require(tidyr)
require(dplyr)
require(lazyeval)

df = data.frame(varName=c(1,2))

收集作品:

df %>% gather(variable,value,varName)

但我希望能够在标准评估模式下从变量中获取名称 varName,但似乎无法正确执行:

name='varName'
df %>% gather_("variable","value",interp(~v,v=name))
Error in match(x, y, 0L) : 'match' requires vector arguments

我也对以下内容感到困惑。

这按预期工作:

df %>% gather_("variable","value","varName")

下一行应该相当于最后一行(根据我对 http://cran.r-project.org/web/packages/dplyr/vignettes/nse.html 的理解),但不起作用:

df %>% gather_(~variable,~value,~varName)
Error in match(x, y, 0L) : 'match' requires vector arguments

最佳答案

查看tidyr:::gather_.data.frame的源代码,您可以看到它只是reshape2::melt的包装器。因此,它仅适用于字符或数字参数。实际上,以下内容(我认为这是一个错误)有效:

df %>% gather_("variable", "value", 1)

据我所知,nse 小插图仅指 dplyr 而不是 tidyr

关于r - Gather_ 不起作用。在标准评估模式下引用和〜ing不应该具有相同的效果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29537848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com