我尝试通过for循环在R中追加几个 Dataframe ,但以下代码无法工作:
rm(list = ls())
# ------------------------------------------------------------------------------
# Libraries
# ------------------------------------------------------------------------------
library("dplyr")
library("readxl")
date <- "202203"
startwave <- 2010
endwave <- 2018
# ------------------------------------------------------------------------------
# Paths and Files
# ------------------------------------------------------------------------------
dell <- 1
if (dell == 1) {
computer <- "C:/Users/jj22684/"
} else {
computer <- "C:/Users/lenovo/"
}
Main_path <- paste(computer, "Dropbox/DATA/REGCON", sep = "")
raw_path <- paste(computer, "Dropbox/DATA/REGCON/RAW files", sep = "")
# REGCON_PATHS
# ------------------------------------------------------------------------------
# Import
# ------------------------------------------------------------------------------
for (y in endwave:startwave) {
FIRMCAtemp <- read_excel(paste(raw_path, "/Datos_totales_", y, "_REGCON.xlsx", sep = ""))
assign(toString(y),y)
FIRMCAtemp$year <- y
assign(paste("FIRMCA", y, sep = ""),FIRMCAtemp)
}
for (y in startwave:endwave) {
FIRMCAtemp <- rbind(FIRMCAtemp,paste("FIRMCA", y, sep = ""))
}
我也尝试过使用sym()函数,它也不起作用。
如果有人能给予我一些如何进行的想法,我将非常感谢。
KR鲁本
1条答案
按热度按时间vmdwslir1#
一种选择是使用
lapply
将XL文件读入列表,并使用dplyr::bind_rows
将它们绑定到一个df中。使用一些虚假的示例数据: