开发者

Column count by element

how do achieve the equivalent of awk '{print $1}' /tmp/data | sort | uniq -c for a particular column in R?

Example: cat /tmp/data

alama 
alama
a开发者_JAVA技巧lama
bbbb
bbbb
ccc
alama
bbbb
bbbb

awk '{print $1}' /tmp/data | sort | uniq -c

  1 
  4 alama
  4 bbbb
  1 ccc

i.e. count of every item in the column.


Based on @Joshua's suggestion and my particular needs ...

s<-data.frame(table(spam[,1]))
p<-s[s$Freq>=3,]
p[order(p$Freq,decreasing=TRUE ),]


> set.seed(21)
> Data <- data.frame(V1=sample(letters[1:5],20,TRUE))
> length(unique(Data[,1]))
[1] 5

Based on your updated question -- assuming data is in x:

> table(x)
x
alama  bbbb   ccc 
    4     4     1 
> data.frame(table(x))
      x Freq
1 alama    4
2  bbbb    4
3   ccc    1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜