2013-05-07 61 views
0

我有一個數據幀,看起來像這樣:在數據幀轉換元件到表中的列

$RandArcBo1 
$RandArcBo1$x 
[1] 150.5 166.5 135.5 177.5 -146.5 153.5 -152.5 152.5 157.5 -174.5 -155.5 -139.5 -129.5 136.5 -157.5 73.5 

$RandArcBo1$y 
[1] 53.56732 78.56732 79.56732 58.56732 73.56732 57.56732 74.56732 55.56732 50.56732 84.56732 82.56732 81.56732 83.56732 78.56732 
[15] 73.56732 73.56732 

$RandArcBo1$Species 
[1] "RandArcBo1" 

我想數據幀轉換爲其中每個數據幀元素對應的列在一個表表如下:

Species  x    y 
RandArcBo1 150.5   53.56732 
RandArcBo1 166.5   78.56732 

..等等。

我已經嘗試過使用xtabs(),但似乎無法以不會導致錯誤的方式對代碼進行短語,而且我也在研究重塑包,但到目前爲止,我一直受到阻礙。有任何想法嗎?

+2

這看起來像一個列表,而不是一個數據幀。你可以在有問題的對象上提供'dput()'的輸出嗎? – joran 2013-05-07 22:02:25

+1

你試過'as.data.frame(。)'嗎? – Arun 2013-05-07 22:04:46

+1

您有包含列表的列表。只要做'as.data.frame(dat $ RandArcBo1)'。 – flodel 2013-05-08 02:55:15

回答

1

使用data.table包,它會做,你似乎想回收:

l = list(x = c(1:10), y = c(11:20), species = "test") 

library(data.table) 
as.data.table(l) 
#  x y species 
# 1: 1 11 test 
# 2: 2 12 test 
# 3: 3 13 test 
# 4: 4 14 test 
# 5: 5 15 test 
# 6: 6 16 test 
# 7: 7 17 test 
# 8: 8 18 test 
# 9: 9 19 test 
#10: 10 20 test