Home > Software engineering >  how to get frequency of different lists, in list of lists
how to get frequency of different lists, in list of lists

Time:10-19

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 r list

CodePudding user response:

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 

CodePudding user response:

What's wrong with sapply and toString:

> table(sapply(test, toString))

      a a, b, c     a,c 
      1       2       2 
> 
  •  Tags:  
  • r
  • Related