从长格式创建频率表

时间:2019-04-02 23:42:34

标签: r

从较长的数据帧开始

data <- data.frame(samples = c("species1","species2","species1"), sample = c("panda","tiger","tiger"))

我们如何得出频率表?

以下是预期输出的示例。

data_st <- data.frame(samples = c("species1","species2"), pande=c(1,0), tiger=c(1,1))


> data_st
>        samples pande tiger
>     1 species1     1     1
>     2 species2     0     1

1 个答案:

答案 0 :(得分:0)

> table(data)
          sample
samples    panda tiger
  species1     1     1
  species2     0     1