dat <- list(list(structure(list(ID = 1, Gender = structure(1L, .Label = "Male", class = "factor"),
Phrase = structure(1L, .Label = "Hello", class = "factor"),
Phrase2 = structure(1L, .Label = "Goodbye", class = "factor")), .Names = c("ID",
"Gender", "Phrase", "Phrase2"), row.names = c(NA, -1L), class = "data.frame"),
structure(list(ID = 1, Gender = structure(1L, .Label = "Female", class = "factor"),
Phrase = structure(1L, .Label = "Good afternoon", class = "factor"),
Phrase2 = structure(1L, .Label = "Goodbye", class = "factor")), .Names = c("ID",
"Gender", "Phrase", "Phrase2"), row.names = c(NA, -1L), class = "data.frame")),
list(structure(list(ID = 2, Gender = structure(1L, .Label = "Male", class = "factor"),
Phrase = structure(1L, .Label = "Hello", class = "factor"),
Phrase2 = structure(1L, .Label = "Good afternoon", class = "factor")), .Names = c("ID",
"Gender", "Phrase", "Phrase2"), row.names = c(NA, -1L), class = "data.frame"),
structure(list(ID = 2, Gender = structure(1L, .Label = "Female", class = "factor"),
Phrase = structure(1L, .Label = "Goodbye", class = "factor"),
Phrase2 = structure(1L, .Label = "Goodbye", class = "factor")), .Names = c("ID",
"Gender", "Phrase", "Phrase2"), row.names = c(NA, -1L
), class = "data.frame")))
> dat
[[1]]
[[1]][[1]]
ID Gender Phrase Phrase2
1 1 Male Hello Goodbye
[[1]][[2]]
ID Gender Phrase Phrase2
1 1 Female Good afternoon Goodbye
[[2]]
[[2]][[1]]
ID Gender Phrase Phrase2
1 2 Male Hello Good afternoon
[[2]][[2]]
ID Gender Phrase Phrase2
1 2 Female Goodbye Goodbye
У меня есть список data.frames, который называется dat
, в котором в каждом элементе списка есть несколько записей (например, по полу).Как я могу объединить этот список data.frames в один data.frame, который выглядит следующим образом?
ID Gender Phrase Phrase2
1 1 Male Hello Goodbye
2 1 Female Good afternoon Goodbye
3 2 Male Hello Good afternoon
4 2 Female Goodbye Goodbye
Я пробовал ldply(dat, data.frame)
, do.call("rbind", dat)
и rbind.fill(dat)
безрезультатно.