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
This is a simple solution with the function aggregate:
aggregate
aggregate(order_no ~ name, myvec, function(x) length(unique(x)))