0

I want to count occurrences of each value for each names() across a list (alt a vector)

lst <- list(`a,b`=1, `b,a`=2, `a,b`=2, `b,a`=1,`a,b`=1,`a,b`=2,`b,a`=1) # list
vec <- unlist(lst) # vector
# ether list or vector would work

I can't figure out to go about this. I've tried different alternatives using table(), tabulation(), str_count(), or e.g. sapply(names(lst), function(x) sum(sapply(vec, function(y) all(y==x))))

For the above dummy example, the desired output would look something like:

$`a,b`
1: 2
2: 2

$`b,a`
1: 2
2: 1

Any pointers would be much appreciated, thanks!

jO.
  • 3,384
  • 7
  • 28
  • 38

0 Answers0