Warm tip: This article is reproduced from stackoverflow.com, please click
dplyr pipe r

Tracking down an R bug with pair-frequency counting

发布于 2020-04-11 22:03:28

A few days ago this code was working well, but now it has broken:

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.

This expression was working until now, just this morning re-ran the code, tried tracing back, I don't know what's going on.

Questioner
UltaPitt
Viewed
89
community wiki 2020-02-02 21:13

(Posting a solution on behalf of the question author to move it to the answer space).

Solution to this was given by rawr and akrun, it was basically me missing the scope resolution for count() function, should've been dplyr::count().