How do I get a contingency table?

后端 未结 6 1659
感动是毒
感动是毒 2020-11-21 23:27

I am trying to create a contingency table from a particular type of data. This would be doable with loops etc... but because my final table would contain more than 10E5 cell

6条回答
  •  耶瑟儿~
    2020-11-22 00:00

    Simply use dcast() function of "reshape2" package:

    ans = dcast( df, PLANT~ ANIMAL,value.var = "INTERACTIONS", fill = 0 ) 
    

    Here "PLANT" will be on the left column, "ANIMALS" on the top row, filling of the table will happen using "INTERACTIONS" and "NULL" values will be filled using 0's.

提交回复
热议问题