我知道如何单独做到这一点。但是,我有超过 1000 个文件。我决定使用 for 循环。但是,似乎我没有找到评估变量的正确方法。
这是我的代码
setwd('C:/data')
filenames=dir() #find file names
for (i in filenames){
adt = substr(x = i, start = 1, stop = nchar(i)-4)
name=paste("data_", adt, sep="")
assign(name, read.csv(i,header=T,sep=",")) #read each file and assign a variable name starting with data_ to it
func=paste('name[is.na(name)] <- 0',sep="") # here is the place I have problem. R will not consider name is a parameter whose values change in each iteration
eval((text=func))
}