简体   繁体   English

如何在列表列表中获取不同列表的频率

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

Suppose i have the following list:假设我有以下列表:

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

I want this as result:我想要这样的结果:

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

I tried with我试过

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

Here is a one-liner.这是一个单线。 The upper row of numbers are the vector's names.上面一行数字是向量的名称。

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

What's wrong with sapply and toString : 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