我有两列“名称”和“链接”,表示公司名称和废品链接。如何放回名称列,以便每一行报废数据都有一个具有相应公司名称的列?
List.Of.Tabs <- map(pages, ~ {
name <- .x[1]
link <- .x[2]
webpage <- read_html(link)
tbls <- html_nodes(webpage, "table")
tbls_ls <- html_table(tbls,fill = TRUE)
pos1 <- possibly(function(tbls) bind_rows(tbls) %>%
filter_all(any_vars(. %in% c("Ireland", "Japan")))
, otherwise = NA)
pos1(tbls_ls)
结果应该是这样的:
results <- data.frame(subsidiaries = c('Microsoft Japan','Microsoft Ireland'),
country = c('Japan', 'Ireland'),
name = c('Microsoft','Microsoft'))
基于代码,我们可能需要mutate
(即在第一行代码中从已创建的'name'创建'name'列)
List.Of.Tabs <- map(pages, ~ {
name <- .x[1]
link <- .x[2]
webpage <- read_html(link)
tbls <- html_nodes(webpage, "table")
tbls_ls <- html_table(tbls,fill = TRUE)
pos1 <- possibly(function(tbls) bind_rows(tbls) %>%
filter_all(any_vars(. %in% c("Ireland", "Japan"))) %>%
mutate(name = name) # changed here
, otherwise = NA)
pos1(tbls_ls)
})