我如何full_join数据帧列表列表 [英] How can I full_join list list of list of dataframes
本文介绍了我如何full_join数据帧列表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从一个站点读取了多个URL,现在有一个数据帧列表(tbl)的列表.现在,我需要将这些数据帧列表全部_加入一个数据帧中.
I read multiple urls from a site and now have a list of list of data frames (tbl). Now I need to full_join these lists of data frames into one data frame.
library(xml2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(purrr)
library(rvest)
#>
#> Attaching package: 'rvest'
#> The following object is masked from 'package:purrr':
#>
#> pluck
url <- file.path(str_c("https://amx.am/en/9/trading/10/instruments", '?page=', 1:3))
#> Error in str_c("https://amx.am/en/9/trading/10/instruments", "?page=", : could not find function "str_c"
tbl <- lapply(url, read_html) %>% lapply(html_table)
#> Error in UseMethod("read_xml"): no applicable method for 'read_xml' applied to an object of class "name"
由 reprex软件包(v0.3.0)于2020-01-25创建
Created on 2020-01-25 by the reprex package (v0.3.0)
推荐答案
每个url
中都有多个表,因此可以将它们组合在一起
Each url
has multiple tables in them so to combine them together you can use
library(rvest)
library(purrr)
library(dplyr)
map(url, ~read_html(.x) %>% html_table) %>%
flatten() %>%
bind_rows()
或者如果您想将它们一起full_join
,我们可以使用reduce
Or if you want to full_join
them together, we can do that with reduce
map(url, ~read_html(.x) %>% html_table) %>%
flatten() %>%
reduce(full_join))
这篇关于我如何full_join数据帧列表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文