두 data.frames firstdf 및 secondf, (아래 예제 데이터.) 나는 아래있는 ExampleList 데이터 같은 결과를 출력 할 함수를 만들려고 해요. firstdf에서 첫 번째 행 항목을 가져 와서 exampleList의 thing 및 test 필드에 값을 넣은 다음 seconddf의 otherthing 필드에서 처음 세 값을 가져 와서 함께 연결하고 저장하는 목록 목록을 만들고 싶습니다. 그런 다음 exampleList의 otherthing 필드에서 firstdf의 다음 행과 seconddf의 다음 3 행으로 이동합니다. 루프는 나에게 조금 까다 롭습니다. 따라서 팁은 분명히 높이 평가됩니다.두 data.frames에서 목록의 목록을 만드는 기능
data:
dput(firstdf)
structure(list(thing = structure(1:3, .Label = c("thing1", "thing2",
"thing3"), class = "factor"), test = structure(1:3, .Label = c("test1",
"test2", "test3"), class = "factor")), .Names = c("thing", "test"
), row.names = c(NA, -3L), class = "data.frame")
dput(seconddf)
structure(list(otherthing = structure(c(4L, 5L, 6L, 7L, 8L, 9L,
1L, 2L, 3L), .Label = c("thing10", "thing11", "thing12", "thing4",
"thing5", "thing6", "thing7", "thing8", "thing9"), class = "factor"),
other = structure(c(9L, 6L, 7L, 2L, 3L, 1L, 8L, 4L, 5L), .Label = c("fads",
"oiu", "qwer", "rewa", "rewq", "sfas", "sfwg", "tre", "xdfs"
), class = "factor")), .Names = c("otherthing", "other"), row.names = c(NA,
-9L), class = "data.frame")
그리고 출력 :
이dput(ExampleList)
list(structure(list(thing = "thing1", test = "test1", otherthing = c("thing4",
"thing5", "thing6")), .Names = c("thing", "test", "otherthing"
)), structure(list(thing = "thing2", test = "test2", otherthing = c("thing7",
"thing8", "thing9")), .Names = c("thing", "test", "otherthing"
)), structure(list(thing = "thing3", test = "test3", otherthing = c("thing10",
"thing11", "thing12")), .Names = c("thing", "test", "otherthing"
)))
[[1]]
[[1]]$thing
[1] "thing1"
[[1]]$test
[1] "test1"
[[1]]$otherthing
[1] "thing4" "thing5" "thing6"
[[2]]
[[2]]$thing
[1] "thing2"
[[2]]$test
[1] "test2"
[[2]]$otherthing
[1] "thing7" "thing8" "thing9"
[[3]]
[[3]]$thing
[1] "thing3"
[[3]]$test
[1] "test3"
[[3]]$otherthing
[1] "thing10" "thing11" "thing12"
가능한 복제 http://stackoverflow.com/questions/26177565/converting-nested-list-to-dataframe – akrun
@akrun 중복으로 망치질 기꺼이 하겠지만, 그 imho에 대해 더 나은 목표가 필요합니다. – Jaap
나는 가능한 한 긍정적 인 말을하지 않았습니다. – akrun