r - 将列表列表转换为长格式的数据框
问题描述
我有一个列表列表
list_of_lists <- list(a = 1,
b = 2:3,
c = 4:6)
我想将其转换为两列的“长格式”数据框。就像是
> rbind(data.frame(KEY = names(list_of_lists)[1], VALUE = list_of_lists[[1]]),
data.frame(KEY = names(list_of_lists)[2], VALUE = list_of_lists[[2]]),
data.frame(KEY = names(list_of_lists)[3], VALUE = list_of_lists[[3]]))
KEY VALUE
1 a 1
2 b 2
3 b 3
4 c 4
5 c 5
6 c 6
我会知道如何用循环解决这个问题,但必须有更直接的方法来做到这一点。我试图重新调整这个问题的用途,但对裁缝对我的问题的答案缺乏足够的理解。
奖金,如果有一个dplyr
-style 解决方案。
解决方案
推荐阅读
- codeigniter - 使用 where 子句时如何避免结果数组中的重复行
- javascript - 当我通过 vuejs 中的后退按钮返回相同的 URL 时,是否可以获得相同的组件数据属性?
- sql - 如何以 1-1 关系将数据存储到表中(单事务)
- quasar-framework - 任何人在 ios 13.4.1 ( 最新版本 ) 上遇到问题
- sql - Redshift:按范围分组行并添加到输出列
- r - 如何从多面体 sf R 中提取经纬度
- jestjs - gitlab-ci 在monorepo中开玩笑,相互依赖
- javascript - 第一次重载后忽略打字稿重载
- css - 如何在 JqGrid 的外部 css 文件中存储自定义 css
- python - 将提取的数据帧标头添加到现有的数据帧 pandas