How to produce an R count matrix

前端 未结 1 815
故里飘歌
故里飘歌 2021-01-07 13:39

In R, I can return the count results using the specific column names I am interested in as an array as below.

require(\"plyr\")
bevs <- data.frame(cbind(n         


        
1条回答
  •  执念已碎
    2021-01-07 14:04

    You want a contingency table, which you can create using table:

    table(bevs[, c("name", "drink")])
    #      drink
    #name   cocoa coffee tea water
    #  Bill     2      2   0     0
    #  Llib     0      0   2     2
    

    0 讨论(0)
提交回复
热议问题