Я собираю информацию о коммерции через API Facebook, и возвращающийся формат данных - это вложенные списки.Я упростил данные до единого списка списков.Данные на уровне 1 согласуются.Данные на уровне 2 всегда содержатся в списке, называемом «действиями», но нерегулярны, поскольку количество элементов в этом подсписке варьируется.Если для этого наблюдения нет действий, то подсписок actions
отсутствует.
Я бы хотел объединить все это в один фрейм данных, чтобы общее дополнение столбцов представляло все возможныеэлементы, содержащиеся в подсписках «действий» уровня 2.Если что-то отсутствует в действиях, то вставляется NA
.
Я бы предпочел использовать пакет purrr
.
Пример данных:
my_list <- list(list(objective = "CONVERSIONS",
impressions = "4318", actions = list(list(action_device = "other",
action_type = "page_engagement", value = "2"), list(action_device = "other",
action_type = "post_engagement", value = "2"), list(action_device = "other",
action_type = "post_reaction", value = "1"), list(action_device = "other",
action_type = "video_view", value = "1"), list(action_device = "desktop",
action_type = "landing_page_view", value = "1"), list(
action_device = "desktop", action_type = "link_click",
value = "1"), list(action_device = "desktop", action_type = "page_engagement",
value = "18"), list(action_device = "desktop", action_type = "post_engagement",
value = "18"), list(action_device = "desktop", action_type = "video_view",
value = "17"), list(action_device = "iphone", action_type = "post",
value = "1"), list(action_device = "iphone", action_type = "landing_page_view",
value = "27"), list(action_device = "iphone", action_type = "link_click",
value = "30"), list(action_device = "iphone", action_type = "page_engagement",
value = "580"), list(action_device = "iphone", action_type = "post_engagement",
value = "580"), list(action_device = "iphone", action_type = "post_reaction",
value = "6"), list(action_device = "iphone", action_type = "video_view",
value = "543"), list(action_device = "ipad", action_type = "landing_page_view",
value = "2"), list(action_device = "ipad", action_type = "link_click",
value = "2"), list(action_device = "ipad", action_type = "page_engagement",
value = "29"), list(action_device = "ipad", action_type = "post_engagement",
value = "29"), list(action_device = "ipad", action_type = "video_view",
value = "27"), list(action_device = "android_smartphone",
action_type = "landing_page_view", value = "11"), list(
action_device = "android_smartphone", action_type = "link_click",
value = "12"), list(action_device = "android_smartphone",
action_type = "page_engagement", value = "222"), list(
action_device = "android_smartphone", action_type = "post_engagement",
value = "222"), list(action_device = "android_smartphone",
action_type = "post_reaction", value = "9"), list(action_device = "android_smartphone",
action_type = "video_view", value = "201"), list(action_device = "android_tablet",
action_type = "landing_page_view", value = "1"), list(
action_device = "android_tablet", action_type = "link_click",
value = "1"), list(action_device = "android_tablet",
action_type = "page_engagement", value = "7"), list(action_device = "android_tablet",
action_type = "post_engagement", value = "7"), list(action_device = "android_tablet",
action_type = "post_reaction", value = "1"), list(action_device = "android_tablet",
action_type = "video_view", value = "5")), date_start = "2018-09-23",
date_stop = "2018-09-23"), list(objective = "CONVERSIONS",
impressions = "8",
date_start = "2018-09-23", date_stop = "2018-09-23"), list(objective = "CONVERSIONS",
impressions = "75", actions = list(list(action_device = "desktop",
action_type = "page_engagement", value = "2"), list(action_device = "desktop",
action_type = "post_engagement", value = "2"), list(action_device = "desktop",
action_type = "video_view", value = "2"), list(action_device = "iphone",
action_type = "page_engagement", value = "12"), list(
action_device = "iphone", action_type = "post_engagement",
value = "12"), list(action_device = "iphone", action_type = "video_view",
value = "12"), list(action_device = "ipad", action_type = "page_engagement",
value = "5"), list(action_device = "ipad", action_type = "post_engagement",
value = "5"), list(action_device = "ipad", action_type = "video_view",
value = "5"), list(action_device = "android_smartphone",
action_type = "page_engagement", value = "3"), list(action_device = "android_smartphone",
action_type = "post_engagement", value = "3"), list(action_device = "android_smartphone",
action_type = "video_view", value = "3")), date_start = "2018-09-23",
date_stop = "2018-09-23"), list(objective = "CONVERSIONS",
impressions = "54",
actions = list(list(action_device = "iphone", action_type = "page_engagement",
value = "5"), list(action_device = "iphone", action_type = "post_engagement",
value = "5"), list(action_device = "iphone", action_type = "video_view",
value = "5"), list(action_device = "android_smartphone",
action_type = "page_engagement", value = "2"), list(action_device = "android_smartphone",
action_type = "post_engagement", value = "2"), list(action_device = "android_smartphone",
action_type = "video_view", value = "2")), date_start = "2018-09-23",
date_stop = "2018-09-23"))