【发布时间】:2015-07-21 14:47:32
【问题描述】:
我在名为 data 的列表中有以下示例数据
data <- structure(list(`1.1` = structure(list(id = structure(1, .Dim = c(1L,
1L)), Sample = structure("Test1", .Dim = c(1L, 1L)), Add = structure("T", .Dim = c(1L,
1L))), .Names = c("id", "Sample", "Add")), `2.1` = structure(list(
id = structure(5, .Dim = c(1L, 1L)), Sample = structure("Test2", .Dim = c(1L,
1L)), Add = structure("A", .Dim = c(1L, 1L))), .Names = c("id",
"Sample", "Add")), `3.1` = structure(list(id = structure(7, .Dim = c(1L,
1L)), Sample = structure("Test3", .Dim = c(1L, 1L)), Add = structure("D", .Dim = c(1L,
1L))), .Names = c("id", "Sample", "Add")), `4.1` = structure(list(
id = structure(12, .Dim = c(1L, 1L)), Sample = structure("Test4", .Dim = c(1L,
1L)), Add = structure("Z", .Dim = c(1L, 1L))), .Names = c("id",
"Sample", "Add")), `5.1` = structure(list(id = structure(17, .Dim = c(1L,
1L)), Sample = structure("Test12", .Dim = c(1L, 1L)), Add = structure("E", .Dim = c(1L,
1L))), .Names = c("id", "Sample", "Add"))), .Names = c("1.1",
"2.1", "3.1", "4.1", "5.1"), row.names = c("id", "Sample", "Add"
), class = "data.frame")
看起来像这样:
data
1.1 2.1 3.1 4.1 5.1
id 1 5 7 12 17
Sample Test1 Test2 Test3 Test4 Test12
Add T A D Z E
如何根据 ID 号将此列表按列拆分为多个 data.frame?例如。是否创建了一个名为 data.ID1 的 data.frame 和一个名为 data.ID5 的 data.frame 和一个名为 data.ID 7 等的 data.frame(参见下面的示例)? data.frame 的名称应与 ID 号相同。我的列表包含大约 700 个不同的 ID 和数据...
data.ID1
id 1
Sample Test1
Add T
data.ID5
id 5
Sample Test2
Add A
data.ID7
id 7
Sample Test3
Add D
等等……
【问题讨论】:
-
id 值是否唯一?
-
是的,它们是独一无二的。
-
看看你想要的输出,你想保持相同的格式(即 id、Sample、Add as row.names)......我是正确的还是你想把它们变成列名字?
-
是的,情况正是如此。行名称是 id、Sample 和 Add。