我已經在列表下面的示例數據稱爲data
R:拆分列表中列和轉化爲新的data.frames
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.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值獨特之處? – digEmAll
是的,它們是獨一無二的。 – nebuloso
看着你想要的輸出看起來,你想保持相同的格式(即ID,樣本,添加爲row.names)...我是否正確或你想把它們變成列名? – digEmAll