2014-02-23 31 views
2

列的值,說我有一個數據幀是這樣的:排序中的每一行數據幀由

Date  A B C D E H 
1/28/2013 56 51 35 44 08 18 
1/25/2013 38 56 28 39 23 32 
1/21/2013 36 51 45 25 40 08 

我想要做的是排序它們的值每行的ABCDE列。因此,我可以得到的是:

Date  A B C D E H  
1/28/2013 08 35 44 51 56 18 
1/25/2013 23 28 38 39 56 32 
1/21/2013 25 36 40 45 51 08 
+0

請閱讀如何以[可重現格式](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)發佈數據,例如,使用'dput'。 – Thomas

回答

2

您可以使用apply

dat[c("A", "B", "C", "D", "E")] <- t(apply(dat[c("A", "B", "C", "D", "E")], 
              1, sort)) 

#  Date A B C D E H 
# 1 1/28/2013 8 35 44 51 56 18 
# 2 1/25/2013 23 28 38 39 56 32 
# 3 1/21/2013 25 36 40 45 51 8 

其中dat是你的數據幀的名稱。

+0

謝謝!得到它了! – ToToRo