I have a dataset that looks like this:
Sample AlgoA AlgoB
A001 R1 R1
A002 R2 R3
A003 R1 R1
A004 R3 R2
A005 R1 R1
A006 R2 R2
A007 R1 R3
A008 R3 R3
I want to summarize this table with the counts of each combination of results. For example, x samples had AlgoA and AlgoB give R1 as the value, y samples had AlgoA value R1 and AlgoB value R2, z samples had AlgoA Value R1 and AlgoB value R3, etc for each combination possible (9 combos)
I'm unsure what this type of table is even called, So far I've only been able to get individual counts, ie x samples are R1, y are R2, z are R3, but unable to combine both together as described above.
This is the final table I'm looking for:
Thanks so much
CodePudding user response:
with(df, table(AlgoA, AlgoB))
# AlgoB
# AlgoA R1 R2 R3
# R1 3 0 1
# R2 0 1 1
# R3 0 1 1
Using this data:
df = read.table(text = 'Sample AlgoA AlgoB
A001 R1 R1
A002 R2 R3
A003 R1 R1
A004 R3 R2
A005 R1 R1
A006 R2 R2
A007 R1 R3
A008 R3 R3', header = T)