Using filter with count

前端 未结 1 1584
太阳男子
太阳男子 2020-12-09 17:57

I\'m trying to filter row using the count() helper. What I would like as output are all the rows where the map %>% count(StudentID) = 3.

相关标签:
1条回答
  • 2020-12-09 18:33

    I don't think count is what you looking for. Try n() instead:

    df %>% 
      group_by(StudentID) %>%
      filter(n() == 3)
    
    # Source: local data frame [6 x 6]
    # Groups: StudentID
    # 
    #   StudentID StudentGender Grade  TermName      ScaleName TestRITScore
    # 1       100             M     9 Fall 2010 Language Usage          217
    # 2       100             M    10 2011-2012 Language Usage          220
    # 3       100             M     9 Fall 2010 Reading                 210
    # 4     10022             F     8 Fall 2010 Language Usage          232
    # 5     10022             F     9 2011-2012 Language Usage          240
    # 6     10022             F     8 Fall 2010 Mathematics             242
    
    0 讨论(0)
提交回复
热议问题