简体   繁体   中英

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 :

> table(sapply(test, toString))

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM