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
We can also use aggregate from base R
aggregate
base R
aggregate(cbind(count=A)~B, a, FUN=function(x) length(unique(x))) # B count #1 N 1 #2 Y 2
Based on the OP's expected output
data.frame(count=length(unique(a$A)), count_BisY = length(unique(a$A[a$B=="Y"])))