Counting factor observation via aggregate in R -


my vector

 name   s1   s1   s1   s2   s2   s3 

i need count number of occurrences of each value. expected output this

 names  no.  s1      3  s2      2  s3      1 

i using aggregate function

aggregate(case2$name,by=list(names =case2$name),table) 

it gives me correct result in diagnol matrix form instead of vector in expected output.

if try aggregate function count, here

aggregate(case2$name,by=list(names =case2$name),count) 

it gives me error

error in usemethod("group_by_") :  no applicable method 'group_by_' applied object of class "factor" 

not sure shall that?

agreed table(name) straight forward approach reference correct syntax using aggregate same result is:

aggregate(name, by=list(name), length)


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -