My vector is
Name
s1
s1
s1
s2
s2
s3
I need to count number of occurrences of each value. The expected output is something like this
Names No.
s1 3
s2 2
s3 1
I am using aggregate function for that which is
aggregate(case2$Name,by=list(Names =case2$Name),table)
It gives me the correct result but in diagnol matrix form instead of another vector as in my expected output.
If I try aggregate function with count, as like here
aggregate(case2$Name,by=list(Names =case2$Name),count)
It gives me this error
Error in UseMethod("group_by_") :
no applicable method for 'group_by_' applied to an object of class "factor"
not sure what shall I do with that?
Agreed that
table(Name)
is the most straight forward approach but for reference the correct syntax for usingaggregate
to get the same result is:aggregate(Name, by=list(Name), length)