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
You can just use the built-in R functions tapply with length
tapply
length
tapply(myvec$order_no, myvec$name, FUN = function(x) length(unique(x)))