【发布时间】:2022-10-13 22:16:59
【问题描述】:
我正在使用 tidycensus 读取一些人口普查数据。我从加载变量开始,我这样做的方式真的很笨拙。关于更简洁的方法来编码负载变量位的任何建议,所以我在绑定之前不分别加载 sf1、sf2、sf3 和 sf4?
ReqPkgs <-
c(
'dplyr',
'tidyverse',
'tidycensus',
'sf'
)
ReqPkgs <- as.list(ReqPkgs)
package.check <- lapply(
ReqPkgs,
FUN = function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, dependencies = TRUE)
library(x, character.only = TRUE)
}
}
)
#this is the part I want to tidy up:
vd_20001 <- load_variables(2000, "sf1", cache = TRUE)
vd_20002 <- load_variables(2000, "sf2", cache = TRUE)
vd_20003 <- load_variables(2000, "sf3", cache = TRUE)
vd_20004 <- load_variables(2000, "sf4", cache = TRUE)
vd_2000 <- rbind(vd_20001, vd_20002, vd_20003, vd_20004)
rm(vd_20001, vd_20002, vd_20003, vd_20004)
【问题讨论】:
标签: r tidyverse tidycensus