【问题标题】:R dplyr filter not working right with mildly complex filterR dplyr 过滤器不适用于轻度复杂的过滤器
【发布时间】:2017-01-04 21:40:46
【问题描述】:

dplyr 当我在检查值中有一个列表子集时,过滤器不起作用。 当我分配给变量时,同样的工作。见下面的代码

df1<-data.frame(x=1:26, y=letters, stringsAsFactors = F)
templist<-list(alpha=df1)
res<-df1 %>% filter(y %in% templist$alpha$y)
nrow(res)
[1] 0
tempLetters <- templist$alpha$y
res<-df1 %>% filter(y %in% tempLetters)
nrow(res)
[1] 26

我认为这以前可以正常工作。请帮忙。请注意,根据设计,两个 (y) 中的列名称相同。

我刚刚在 cran 上更新了 dplyrtidyrpipeR 到最新版本(2017 年 1 月 4 日)

【问题讨论】:

  • 我认为这可能是一个错误或名称冲突,尝试使用filter(df1, y %in% templist$alpha[[2]]) 甚至filter(df1, y %in% templist$alpha[["y"]])
  • 你确定filter()是你想要的功能吗? Select() 可能更有用,例如 select(df1$alpha,y) 或列表 select(templist$alpha,y)
  • Andrew 我只是举了一个简单的例子来强调这个问题。 @akrun 你是对的。名称冲突会出现此问题!
  • 此外,它仅在存在第三级间接时才会失败 (list$dataframe$columnname) 例如:df1% filter(y %in% df2$y) nrow(res) 工作得很好

标签: r dplyr


【解决方案1】:

@hadleywickham 已确认这是一个在 dev 中修复的已知错误

请在 Twitter 上查看他的回复: https://twitter.com/gunapemmaraju/status/816639470166544384

【讨论】:

    猜你喜欢
    • 2017-10-06
    • 2023-03-12
    • 2019-04-04
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 2018-03-03
    • 2019-07-13
    相关资源
    最近更新 更多