在 R 中构建嵌套 tibbles 的数据框?
Build a dataframe of nested tibbles in R?
我有几个小问题:
1:
structure(list(contacts = c(151, 2243, 4122, 6833, 76, 123)), .Names = "contacts", row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
2:
structure(list(image_names = c("/storage/emulated/0/Pictures/1.png",
"/storage/emulated/0/Pictures/10.png", "/storage/emulated/0/Pictures/2.png",
"/storage/emulated/0/Pictures/3.png", "/storage/emulated/0/Pictures/4.png",
"/storage/emulated/0/Pictures/5.png")), .Names = "image_names", row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
3:
structure(list(phone_number = c(22881, 74049, 74049, 22881, 22881,
22881), isInContact = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
callDuration = c(1, 0, 0, 71, 13, 54), Date = structure(c(17689,
17689, 17689, 17690, 17690, 17690), class = "Date"), Time = structure(c(76180,
77415, 84620, 27900, 28132, 29396), class = c("hms", "difftime"
), units = "secs")), .Names = c("phone_number", "isInContact",
"callDuration", "Date", "Time"), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
考虑到对于这些数据帧的每一组我都可以获得一个标识符,比如 UUID。
我想构建一个大型数据框 object,其中标识符将是用户的 uuid,所有其他列将是嵌套的小标题:
UUID contacts images call_logs
123 <tibble> <tibble> <tibble>
456 <tibble> <tibble> <tibble>
请告诉我如何构建这样的东西,我正在尝试使用 map_dfr
但运气不好。
我们可以将小标题放在 list
中以创建单行
tblN <- tibble(contacts = list(tbl1), images = list(tbl2),
call_logs = list(tbl3))
不清楚是否应该为不同的“UUID”复制相同的数据集。
list(`123` = tblN, `456` = tblN) %>%
bind_rows(.id = 'UUID')
我有几个小问题:
1:
structure(list(contacts = c(151, 2243, 4122, 6833, 76, 123)), .Names = "contacts", row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
2:
structure(list(image_names = c("/storage/emulated/0/Pictures/1.png",
"/storage/emulated/0/Pictures/10.png", "/storage/emulated/0/Pictures/2.png",
"/storage/emulated/0/Pictures/3.png", "/storage/emulated/0/Pictures/4.png",
"/storage/emulated/0/Pictures/5.png")), .Names = "image_names", row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
3:
structure(list(phone_number = c(22881, 74049, 74049, 22881, 22881,
22881), isInContact = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
callDuration = c(1, 0, 0, 71, 13, 54), Date = structure(c(17689,
17689, 17689, 17690, 17690, 17690), class = "Date"), Time = structure(c(76180,
77415, 84620, 27900, 28132, 29396), class = c("hms", "difftime"
), units = "secs")), .Names = c("phone_number", "isInContact",
"callDuration", "Date", "Time"), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
考虑到对于这些数据帧的每一组我都可以获得一个标识符,比如 UUID。
我想构建一个大型数据框 object,其中标识符将是用户的 uuid,所有其他列将是嵌套的小标题:
UUID contacts images call_logs
123 <tibble> <tibble> <tibble>
456 <tibble> <tibble> <tibble>
请告诉我如何构建这样的东西,我正在尝试使用 map_dfr
但运气不好。
我们可以将小标题放在 list
中以创建单行
tblN <- tibble(contacts = list(tbl1), images = list(tbl2),
call_logs = list(tbl3))
不清楚是否应该为不同的“UUID”复制相同的数据集。
list(`123` = tblN, `456` = tblN) %>%
bind_rows(.id = 'UUID')