2013-02-25 78 views
0

我有以下表重塑data.frame

structure(list(Compound = structure(c(1L, 2L, 3L, 1L, 1L, 3L), .Label = c("Nap", 
"Phe", "tre"), class = "factor"), Area = c(17197669L, 19464754L, 
35792660L, 10097291L, 348395L, 2576352L), Samples = structure(c(1L, 
1L, 1L, 2L, 3L, 2L), .Label = c("a1", "a2", "a3"), class = "factor")), .Names = c("Compound", 
"Area", "Samples"), class = "data.frame", row.names = c(NA, -6L 
)) 

至极我要重新排序因为这

structure(list(Compound = structure(1:3, .Label = c("Nap", "Phe", 
"tre"), class = "factor"), a1 = c(17197669L, 19464754L, 35792660L 
), a2 = c(10097291L, 0L, 2576352L), a3 = c(348395L, 0L, 0L)), .Names = c("Compound", 
"a1", "a2", "a3"), class = "data.frame", row.names = c(NA, -3L 
)) 

什么建议吗?我不知道如何开始。

+2

在R中称为“重塑”必须有数百个已发布的工作示例。做一些搜索。 – 2013-02-25 19:04:20

+0

我很抱歉迪宁,谢谢,这应该让我开始。 – FranciscoC 2013-02-25 19:06:04

回答

2

如果data是你的第一个表,你可以用这个启动:

reshape(data,idvar="Compound",timevar="Samples",direction="wide") 

详见?reshape

+0

谢谢Theodore !!!! – FranciscoC 2013-02-25 19:21:56