【问题标题】:How to convert a nested list of tibbles to a list of data.frames in R [duplicate]如何将嵌套的小标题列表转换为R中的data.frames列表[重复]
【发布时间】:2021-11-03 04:07:37
【问题描述】:

我有嵌套的 tibbles 列表,并希望将其转换为 data.frames 列表

starwars %>% select(homeworld , species , birth_year ) %>% nest_by(homeworld, .keep = F) %>% .$data

因此,在上面的示例中,列表中将有 49 个 data.frame。我怎样才能做到这一点?结果列表必须是 data.frames 而不是 tibbles,这一点很重要,因为我使用的函数只接受 data.frames。

【问题讨论】:

  • 一旦你有了一个 tibbles 列表,只需在它们上调用as.data.frame,例如使用purrr::maplapply
  • 这是正确答案。我试过 %>% data.frame() 但我需要 lapply 是有道理的。很遗憾这个问题已经结束,否则我会投票赞成。
  • 您仍然可以对已关闭问题的答案投票
  • 我赞成你的评论,但它不是作为答案写的
  • 不,我没有将其作为答案发布,因为这需要标记为重复

标签: r dplyr tibble


【解决方案1】:

我认为这可能会有所帮助

starwars %>%
 select(homeworld , species , birth_year ) %>%
 group_split(homeworld)

【讨论】:

  • group_split(homeworld, .keep = FALSE)
  • 谢谢,但嵌套列表仍保留在小标题中
猜你喜欢
  • 2017-08-02
  • 2021-06-09
  • 2021-11-25
  • 1970-01-01
  • 2017-12-12
  • 2016-06-17
  • 1970-01-01
  • 2019-12-18
相关资源
最近更新 更多