Reputation: 5169
I have the following list:
my_list <- structure(list(RandomForest = c("charge.Group2", "polarizability.Group2",
"hydrophobicity.Group1", "KR", "secondarystruct.Group1", "solventaccess.Group1",
"Q", "hydrophobicity.Group2", "normwaalsvolume.Group1", "polarity.Group3"
), rocValues = c("KR", "Q", "KE", "KV", "charge.Group2", "SG",
"MEK", "polarity.Group3", "V", "hydrophobicity.Group1"), ReliefF = c("KR",
"SG", "MEK", "KV", "YH", "EP", "KY", "KYH", "PVK", "KKY"), MIC = c("solventaccess.Group1",
"R", "P", "hydrophobicity.Group2", "Q", "polarity.Group3", "KR",
"polarizability.Group2", "polarity.Group2", "charge.Group1")), .Names = c("RandomForest",
"rocValues", "ReliefF", "MIC"))
my_list
#> $RandomForest
#> [1] "charge.Group2" "polarizability.Group2"
#> [3] "hydrophobicity.Group1" "KR"
#> [5] "secondarystruct.Group1" "solventaccess.Group1"
#> [7] "Q" "hydrophobicity.Group2"
#> [9] "normwaalsvolume.Group1" "polarity.Group3"
#>
#> $rocValues
#> [1] "KR" "Q"
#> [3] "KE" "KV"
#> [5] "charge.Group2" "SG"
#> [7] "MEK" "polarity.Group3"
#> [9] "V" "hydrophobicity.Group1"
#>
#> $ReliefF
#> [1] "KR" "SG" "MEK" "KV" "YH" "EP" "KY" "KYH" "PVK" "KKY"
#>
#> $MIC
#> [1] "solventaccess.Group1" "R"
#> [3] "P" "hydrophobicity.Group2"
#> [5] "Q" "polarity.Group3"
#> [7] "KR" "polarizability.Group2"
#> [9] "polarity.Group2" "charge.Group1"
What I want to do is to create a count table like this:
RandomForest rocValues ReliefF MIC
charge.Group1 0 0 0 1
charge.Group2 1 1 0 0
...
YH 0 0 1 0
How can I achieve that?
Basically, take the content of every named list and count the presence on overall content.
Upvotes: 1
Views: 40
Reputation: 24480
A base
one liner for this:
table(stack(my_list))
# ind
#values RandomForest rocValues ReliefF MIC
# charge.Group1 0 0 0 1
# charge.Group2 1 1 0 0
# EP 0 0 1 0
# hydrophobicity.Group1 1 1 0 0
#....
Upvotes: 4