So I have a list of values:
Value
AAA
BBB
CCC
.
.
.
ZZZ
Now I have a data frame where each row has 15 column that can contain these values as such:
ID V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15
1 AAA
2 AAA BBB
3 CCC BBB
Basically, I'd like a count of rows from this data frame for each value in that list where it can show up in any of the 15 columns:
Desired output:
Value Count
AAA 2
BBB 2
CCC 1
.
.
.
ZZZ 0
I've tried using sapply and apply like the following but this doesn't seem to work:
apply(mylist$values, 2, function(x) { length(which(df[,2:16] %in% x)) } )
or
sapply(mylist$values, function(x) { length(which(x %in% df[,2:16])) })
I'd appreciate any ideas!
Thanks,