r - 如何“取消嵌套”两个不兼容的嵌套 tibble 列?
问题描述
我有一列嵌套的小标题。我想x
将第二行的值转换为一个列表,以便我可以取消嵌套。如何根据列名 ( x
) 及其格式 ( character
) 更改此嵌套列表的值?
tibble(data = c(tibble(x = list(NULL)),
tibble(x = ""))) %>%
unnest(data)
#> Error: Can't combine `..1$data` <list> and `..2$data` <character>.
解决方案
@Duck's comment worked for me.
library(dplyr)
library(tidyr)
tibble(data = c(tibble(x = list(NULL)), tibble(x = ""))) %>%
unnest_wider(data)
Let me try to explain:
tidy::unnest()
struggles to unnest tibbles that have more than one level of nesting. Unnest_wider is capable of "rectangling" which the tidyverse website describes as "the art and craft of taking a deeply nested list (often sourced from wild caught JSON or XML) and taming it into a tidy data set of rows and columns."
Unnest_wider takes each element of a list-column and makes a new column.
推荐阅读
- dictionary - 为什么切片值有时会过时但从不映射值?
- python - 有没有可能将数字列表导入python?
- java - 用于动态修改或删除列表元素的 Java 8 流/映射/过滤器
- c# - DropCreateDatabaseAlways - 删除数据库或架构?
- lua - 引用变量的Lua问题
- java - 从 Tomcat 7 迁移到 Tomcat 9,页面需要重新加载/刷新才能工作
- c# - Razor 运行时重新编译似乎不适用于 *.razor 组件文件
- unity3d - 如何为其他加入的玩家更改颜色?
- angular - 如何在打字稿中选择键值[object:object]?
- python - MyPy - 您如何在注释中实际使用类型化存根?