订购频率表

时间:2016-02-27 17:21:37

标签: r

这是我的两个矩阵,第一个是颜色的名称和他的反应时间,第二个是颜色,成分和实验数量的名称。

DF1 <- read.table(text = "   color     time      
                               A        14         
                               B        5         
                               C        15         ", header = TRUE)




DF2 <- read.table(text = "   color     comp     exp
                               A        c0        12
                               B        c3        12
                               C        c4        1
                               A        c7        13", header = TRUE)


datas <- merge(x=DF1, y=DF2, by.x='color', by.y='color')
        datas  <- datas [order(datas$time),]


table(datas$comp,datas$color)

我想要一张颜色频率的表格,但是根据它们各自的反应时间(ascendent)排序,我得到的是

     A B C
  c0 1 0 0
  c3 0 1 0
  c4 0 0 1
  c7 1 0 0

我正在寻找:

     B A C
  c0 0 1 0
  c3 1 0 0
  c4 0 0 1
  c7 0 1 0

怎么做?

非常感谢!

1 个答案:

答案 0 :(得分:2)

table(datas$comp,datas$color)[, DF1$color[order(DF1$time)]]
#     B A C
#  c0 0 1 0
#  c3 1 0 0
#  c4 0 0 1
#  c7 0 1 0
相关问题