【问题标题】:Reshaping a data.frame重塑 data.frame
【发布时间】:2013-02-25 19:00:55
【问题描述】:

我有下表

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
))

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

【问题讨论】:

  • 这在 R 中被称为“重塑” 必须已经发布了数百个工作示例。做一些搜索。
  • 我很抱歉 DWin,谢谢,这应该让我开始。

标签: r reshape reshape2


【解决方案1】:

如果data 是你的第一个表,你可以从这个开始:

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

详情请见?reshape。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2021-10-02
    • 2021-10-26
    • 1970-01-01
    相关资源
    最近更新 更多