当使用TidyCensus提取ACS数据时,我使用map_dfr循环查看“地点”地理位置的多年数据。我使用的模板是here和here。
我收到以下错误,我坚持调试它。希望你能帮我搞清楚到底发生了什么。谢谢。
library(tidycensus, tidyverse, purrr)
#list years
years <- lst(2011:2020)
names(years) <- years
# census variables
my_vars <- c(
total_pop = "B01003_001",
pop_poverty = "B17001_001"
)
# loop over list of years and get 1 year acs estimates
multi_year <- map_dfr(
years,
~ {get_acs(
geography = "place",
variables = my_vars,
year = .x,
survey = "acs1",
geometry = FALSE
)
},
.id = "year" # when combining results, add id var (name of list item)
) %>%
filter(GEOID = 0644000) %>%
select(-moe) %>%
arrange(variable, NAME) %>%
print()
Getting data from the 2011 1-year ACSGetting data from the 2012 1-year ACSGetting data from the 2013 1-year ACSGetting data from the 2014 1-year ACSGetting data from the 2015 1-year ACSGetting data from the 2016 1-year ACSGetting data from the 2017 1-year ACSGetting data from the 2018 1-year ACSGetting data from the 2019 1-year ACSGetting data from the 2020 1-year ACS
The 1-year ACS provides data for geographies with populations of 65,000 and greater.
Error in `map()`:
ℹ In index: 1.
ℹ With name: 2011:2020.
Caused by error in `parse_url()`:
! length(url) == 1 is not TRUE
Run `rlang::last_trace()` to see where the error occurred.
Warning messages:
1: In if (year < 2005) { :
the condition has length > 1 and only the first element will be used
2: In if (year < 2013) { :
the condition has length > 1 and only the first element will be used
3: In if (year < 2013) { :
the condition has length > 1 and only the first element will be used
1条答案
按热度按时间8xiog9wr1#
问题是使用
dplyr::lst(2011:2012)
创建了一个只有一个元素的list
,即avector
年:因此,不是在
years
上循环,而是向get_acs
传递vector
年。相反,使用命名的vector来实现所需的结果: