簡體   English   中英

如何在列表列表中獲取不同列表的頻率

[英]how to get frequency of different lists, in list of lists

假設我有以下列表:

test<-list(c("a","b","c"),c("a,c"),c("a,c"),c("a","b","c"),c("a"))

我想要這樣的結果:

("a","b","c") = 2
("a,c")=2
("a")=1

我試過

> table(test)
Error in table(test) : all arguments must have the same length

這是一個單線。 上面一行數字是向量的名稱。

table(match(test, unique(test)))
#1 2 3 
#2 2 1 

sapplytoString有什么問題:

> table(sapply(test, toString))

      a a, b, c     a,c 
      1       2       2 
> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM