Let\'s say I have the following data frame:
> myvec name order_no 1 Amy 12 2 Jack 14 3 Jack 16 4 Dave 11 5 Amy
Using table :
table
library(magrittr) myvec %>% unique %>% '['(1) %>% table %>% as.data.frame %>% setNames(c("name","number_of_distinct_orders")) # name number_of_distinct_orders # 1 Amy 2 # 2 Dave 1 # 3 Jack 3 # 4 Larry 1 # 5 Tom 2