【发布时间】:2020-08-23 04:23:11
【问题描述】:
我已经编写了在生物群系的 csv 文件上运行采样函数的代码。 我有 30 个 csv 文件,我想循环这些文件。我正在努力应用我在文件夹中的所有文件中轻松编写的代码。我确信这是一个简单的解决方法,我只是发现循环内的循环存在问题。
temp <- read.csv("tropical_grassland_N_Am_point_summary_table_gdrive.csv")
temp <- temp[which(temp$nd > 0.1),]
index <- substr(temp[,5],30,(nchar(as.character(temp[,5]))-2))
unique_index <- unique(index)
unique_index <- sample(unique_index, 20, replace=F)
for (i in 1:length(unique_index)){
temp2 <- temp[which(index==unique_index[i]),]
theDates = strptime(temp2[,2], format="%Y-%m-%d")
}
thresh <- 0.95
for (i in 1:length(unique_index)){
temp2 <- temp[which(index==unique_index[i]),]
theDates = strptime(temp2[,2], format="%Y-%m-%d")
}
所有的 csv 文件在大陆和生物群落的描述之后都有 _point_summary_table_gdrive.csv 的共同点。
【问题讨论】:
-
你可以从
list.files(pattern="+csv")开始,然后通过文件名循环你的代码。