谁能告诉我我在 r 中的 for 循环只运行一次吗?该脚本只是尝试为大约 5 个主要文件中的大约 200 个子文件的列表创建 csv 文件。这是我的代码:
ImpactGrid<- function(num, condition, CONDITION){
#Set working directiory
for(i in num){
if(i <10){
filename <- paste("./EOBS DATA/ECA_blend_", condition, "/" ,CONDITION, "_STAID00000", i, ".txt", sep = "")
}
if(i >=10 & i < 100){
filename <- paste("./EOBS DATA/ECA_blend_", condition, "/" ,CONDITION, "_STAID0000", i, ".txt", sep = "")
}
if(i>= 100){
filename <- paste("./EOBS DATA/ECA_blend_", condition, "/" ,CONDITION, "_STAID000", i, ".txt", sep = "")
}
con <- file(filename, "r")
data <- readLines(con)
close(con)
q <- data[21:length(data)] # removes non data before the data begins
Impactdata <- read.table(text = q, sep=',',fill=TRUE,colClasses='character',header = TRUE )
Savename <- paste("./EOBS DATA/",condition, "_csv_data/", condition,i, ".csv", sep = "")
write.csv(Impactdata, Savename)
x <- read.csv(paste("./EOBS DATA/",condition, "_csv_data/", condition,i, ".csv", sep = ""))
return(head(x))
}
}