遍历R中for循环中的子目录
我有一个包含365个子目录的大目录,其中包含一年中每一天的图像。我创建了一个函数,希望应用于这些子目录中的每个图像。目前,我所拥有的是:遍历R中for循环中的子目录,r,for-loop,r-raster,R,For Loop,R Raster,我有一个包含365个子目录的大目录,其中包含一年中每一天的图像。我创建了一个函数,希望应用于这些子目录中的每个图像。目前,我所拥有的是: library(raster) library(zebu) #List all of the 365 sub-directories within my main directory days <- list.files(full.names = F , recursive =F, pattern='*X2000*') #Apply my funct
library(raster)
library(zebu)
#List all of the 365 sub-directories within my main directory
days <- list.files(full.names = F , recursive =F, pattern='*X2000*')
#Apply my function to each directory within "days"
for(j in 1:length(days)){
named <- paste0("full_",j)
in.list <- list.files(recursive = T, full.names = F)
stitched <- mosaicList(in.list)
writeRaster(stitched, path='D:/Scratch/DataConvert/Daymet_Data/Full/' ,
filename=named, overwrite=TRUE)
}
我是新来R的,所以我不太确定哪里出了问题。有人对解决这个问题有什么见解吗 循环中的
列表文件出现问题:
in.list <- list.files(recursive = T, full.names = F)
in.list当我尝试你的建议时,我的对象in.list
结果是空的。如果我将我的第一行更改为((j in 1:length(days))的{
并按照您的建议,我的在.list
中被创建并正确地列出了目录中的图像,但是j变成了1L
而不是它应该是的图像。哎呀,我没有更改full.names=t
。我做了更改,现在它正在工作。感谢您的帮助!
in.list <- list.files(recursive = T, full.names = F)
in.list <- list.files(path=days[j], recursive = T, full.names = T)