温馨提示:本文翻译自stackoverflow.com,查看原文请点击:dplyr - Tracking down an R bug with pair-frequency counting
dplyr pipe r

dplyr - 使用对频计数追踪R错误

发布于 2020-04-11 23:12:50

几天前,此代码运行良好,但现在已损坏:

links <- data.frame(source= c(1:3,4,6,8,10,10,12), target= c(1:3,5,1,10,4,4,9))
#View(links)

#source   target
#  1        1
#  2        2
#  3        3
#  4        5
#  6        1
#  8        10
#  10       4
#  10       4
#  12       9

relations <- links %>%
  dplyr::group_by(source, target) %>%
  count()

#View(relations) #Just getting one column with 2 everytime??
# V1
# 2

#Should've been and it used to be-
#source   target   count
#  1        1       1
#  2        2       1
#  3        3       1
#  4        5       1
#  6        1       1
#  8        10      1
#  10       4       2
#  12       9       1

Have tried %>% summarize(count =n()) too, no luck.

该表达式一直有效,直到今天早上才重新运行代码,尝试回溯,但不知道发生了什么。

查看更多

提问者
UltaPitt
被浏览
63
community wiki 2020-02-02 21:13

(代表问题作者发布解决方案以将其移至答案空间)。

Rawr和akrun给出了解决方案,基本上我count()应该错过函数的作用域分辨率,应该是dplyr::count()