So i would like to compute a distinct value of a column. This is the data frame :
asa
----
aa
bb
aa
aa
bb
cc
dd
Want to get :
asa | n
--------
aa | 3
bb | 2
cc | 1
dd | 1
I ve tried using ddply from Counting unique / distinct values by group in a data frame and do this code : (reproducible)
asa<-c("aa","bb","aa","aa","bb","cc","dd")
asad<-data.frame(asa)
ddply(asad,~asa,summarise,n=length(unique(asa)))
But I got :
asa n
1 aa 1
2 bb 1
3 cc 1
4 dd 1
It didnt do the computation. Notes that the value in column can be added anytime. so it is not always "aa","bb","cc",and "dd". Also it can be separated by space or comma ("aa bb" , "aa,bb" or "aa, bb") There must be a way for this. thank you in advance