r - R中的问题映射和未嵌套数据
问题描述
我遇到了一个奇怪的行为(如果我重新启动 Rstudio,此代码可以正常工作,但是如果我在另一个运行此错误的脚本之后运行)。
用 xml2 读取一个 xml 文件
root_players 是一个 14 行 x 13 列的小标题
- node_players 是一个小标题列表
查看代码
library(xml2)
library(tidyverse)
xml_filename <-"file.xml"
# Leer XML
datos <- read_xml(xml_filename)
meta_datos <- datos %>%
xml_attrs() %>%
t() %>%
as_tibble()
root_players <- xml_find_all(datos, '/SoccerFeed/Player') %>%
xml_attrs() %>%
map(~as_tibble(t(.))) %>%
bind_rows()
node_players <- xml_find_all(datos, '/SoccerFeed/Player') %>%
map(~.x %>%
xml_children() %>%
map(function(.y) {.y %>%
xml_attrs() %>%
t() %>%
as_tibble() %>%
mutate(n_passes = xml_text(.y))}) %>%
bind_rows())
#############################
# HERE ERROR APPEARS
############################
root_players <- root_players %>%
mutate(n = map(node_players, count) %>% unlist()) %>%
uncount(weights = n)
#########################
### ERROR TRACE
#########################
Error: Assigned data `eval(cols[[col]], .data, parent.frame())` must be compatible with existing data.
x Existing data has 14 rows.
x Assigned data has 363 rows.
i Only vectors of size 1 are recycled.
<error/tibble_error_assign_incompatible_size>
Assigned data `eval(cols[[col]], .data, parent.frame())` must be compatible with existing data.
x Existing data has 14 rows.
x Assigned data has 363 rows.
i Only vectors of size 1 are recycled.
Backtrace:
Run `rlang::last_trace()` to see the full context
解决方案
推荐阅读
- javascript - npm csv-parse 未读取所有行
- linux - 允许 Apache 在 root 中执行命令?
- r-markdown - 在 r-markdown 中编织/渲染时是否可以指定 .rmd 文件的名称?
- javascript - NodeJS 和 Express;连接查询回调完成
- javascript - 为什么我收到“Select.js:1555 Uncaught TypeError: Cannot read property 'isSelectOptGroup' of undefined”
- php - Var_dump("0") 返回字符串(5) "0"
- excel - 将几个组合框值的总和放入单个文本框中
- c# - 无效 JSON 原始绘制的数据表问题
- google-maps - 地理编码 api 有多少请求是免费的?
- excel - 如何遍历高级筛选器中的条件?