【发布时间】:2019-03-29 18:52:26
【问题描述】:
我想将列表列元素拆分为单独的列。
例如,在星球大战数据集中,
data("starwars")
我想要这个列表列(第 7 行中的条目)
c("Attack of the Clones", "Revenge of the Sith", "A New Hope")
根据电影的值分为 A、B、C... 列
A B C D ...
Attack of the Clones Revenge of the Sith A New Hope NA ...
我想出了一种方法来做到这一点
starwars %>% separate(films, into= letters[1:7],sep = ",")
这将导致输出
A B C D ...
c("Attack of the Clones" "Revenge of the Sith" "A New Hope") NA ...
但这需要一些额外的清理,我认为这不是一般情况。有没有办法一举搞定?
【问题讨论】:
-
您可以使用
map循环浏览列表。但是,您想要的NA尚不清楚 -
NA 将是出现在少于最大数量 (7) 部电影中的角色的值