我有一个非常简单的问题,作为R newb。我想运行一个代码来执行一个函数,然后保存生成的文件。这是我到目前为止所做的:
for (m in 1:30){
drought.slice <- rotate(drought.array[m,,])
drought.vec <- as.vector(drought.slice)
length(drought.vec)
drought.df01 <- data.frame(cbind(lonlat, drought.vec))
names(drought.df01) <- c("lon", "lat", paste(dname,as.character(m), sep = "_"))
head(na.omit(drought.df01))
csvfile <- "cru_drought_[m].csv"
write.table(na.omit(drought.df01), csvfile, row.names = FALSE, sep = ",")
}
但是,当我这样做时,它不会保存文件夹中的文件1到30。我做错了什么?
答案 0 :(得分:2)
csvfile<-paste0("cru_drought_",m,".csv")
另请考虑write.csv