dplyr n_distinct with condition

前端 未结 4 1544
离开以前
离开以前 2021-02-05 17:39

Using dplyr to summarise a dataset, I want to call n_distinct to count the number of unique occurrences in a column. However, I also want to do another summarise() for all uniqu

4条回答
  •  长发绾君心
    2021-02-05 18:28

    Filtering the dataframe before performing the summarise works

    a %>%
      filter(B=="Y") %>%
      summarise(count = n_distinct(A))
    

提交回复
热议问题