2016-02-27 81 views
1

這是我的兩個矩陣,第一個是顏色的名稱和他的反應時間,第二個是顏色的名稱,組成和實驗的次數。訂購頻率表

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) 

我想有顏色的頻率的表,但通過他們各自的反應時間(上升的)排序,我得到是

 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 

該怎麼辦?

非常感謝!

回答

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 
+0

完美,非常感謝! – ranell