r - 将列表取消嵌套到两个单独的列中
问题描述
mutate
我想使用类似函数的 tidyverse 语法将列表取消嵌套到两个单独的列中。
例如:
data %>% mutate_at("centroid", unnest_wider)
给我以下错误:
x
col
缺少参数且没有默认值
我尝试使用分配列名
.cols=c("X", "Y")
在代码中,但我仍然得到错误。
示例数据:
data <- structure(list(disasterno = c("2009-0631", "2009-0631", "2001-0146",
"2009-0092", "2009-0092", "2009-0092"), centroid = structure(list(
structure(c(19.4183172957388, 42.0209484621449), class = c("XY",
"POINT", "sfg")), structure(c(19.5143087402113, 41.9592941221655
), class = c("XY", "POINT", "sfg")), structure(c(15.6657576094231,
-17.093484362207), class = c("XY", "POINT", "sfg")), structure(c(15.7739867740437,
-16.5315326589011), class = c("XY", "POINT", "sfg")), structure(c(15.7739867740437,
-16.5315326589011), class = c("XY", "POINT", "sfg")), structure(c(15.7739867740437,
-16.5315326589011), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT",
"sfc"), precision = 0, bbox = structure(c(xmin = 15.6657576094231,
ymin = -17.093484362207, xmax = 19.5143087402113, ymax = 42.0209484621449
), class = "bbox"), crs = structure(list(input = "EPSG:4326",
wkt = "GEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]"), class = "crs"), n_empty = 0L)), row.names = c(NA,
6L), class = "data.frame")
解决方案
> data %>% tidyr::unnest_wider(centroid)
# A tibble: 6 × 3
disasterno ...1 ...2
<chr> <dbl> <dbl>
1 2009-0631 19.4 42.0
2 2009-0631 19.5 42.0
3 2001-0146 15.7 -17.1
4 2009-0092 15.8 -16.5
5 2009-0092 15.8 -16.5
6 2009-0092 15.8 -16.5
推荐阅读
- react-native - 使用 aws-amplify-react-native 注册时未收到确认码(之前突然失败的作品)
- php - PHP删除匹配模式或通配符模式的标签
- css - 条纹支付选择样式
- javascript - jQuery - 查找同一父行的另一个子元素值
- c# - MsiTriState LinkToFile和MsiTriState SaveWithDocument是什么意思在添加图片到excel C#
- fonts - Angular 8 无法更改字体
- python - 如何在 linux 和 mac 上的 python 中正确使用 .dll 文件
- reactjs - 我的前端和后端没有共享 cookie
- javascript - Ajax Javascript - POST 方法“u”是值的无效开始
- apache-flink - FLINK,基于JSON动态输入数据(如地图对象数据)触发事件