How to remove rows that have only 1 combination for a given ID

前端 未结 4 1862
时光说笑
时光说笑 2020-12-04 02:59

I have a dataframe like this

ID <- c(\"A\",\"A\",\"A\",\"B\",\"B\",\"C\",\"C\")
Measurement <- c (\"Length\",\"Breadth\",\"Breadth\",\"Breadth\",\"Leng         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 03:32

    In dplyr, it would be

    library(dplyr)
    
    df %>% group_by(ID) %>% filter(n_distinct(Measurement) > 1)
    ##       ID Measurement Value
    ##          
    ## 1      A      Length   4.5
    ## 2      A     Breadth   6.6
    ## 3      A     Breadth   7.5
    ## 4      B     Breadth   3.3
    ## 5      B      Length   5.6
    

提交回复
热议问题