Keep only groups of data with multiple observations

前端 未结 2 510
既然无缘
既然无缘 2020-12-19 06:23

I am attempting to keep only deids with multiple observations.

I have the below code

help <- data.frame(deid = c(1, 5, 5, 5, 5, 5, 5, 12, 12, 12,         


        
2条回答
  •  情歌与酒
    2020-12-19 06:58

    this should do it - you need to filter by number of observations in each group which is got using n():

    help %>% group_by(deid) %>% filter(n()>1)
    
      deid session.number days.since.last
    1     5              1               0
    2     5              2               7
    3     5              3              14
    4     5              4              93
    5     5              5               5
    6     5              6             102
    7    12              1               0
    8    12              2              21
    9    12              3             104
    10   12              4               4
    

提交回复
热议问题