我的任务是从一个文件夹中获取多个类似的 NetCDF (.nc
)文件,并在10个变量中堆叠一个a
变量。
我用过:
a <- list.files(path=ncpath, pattern = "nc$", full.names = TRUE)
这使我得到所有扩展名为.nc
的文件。
如何执行第二项任务?
我希望从文件夹中这些数量的文件中使用此变量a
并将其堆叠。
答案 0 :(得分:0)
如果只希望将输出输出到netcdf文件中,则可以考虑在Linux的命令行中使用cdo来执行此任务?
files=$(ls *.nc) # you might want to be more selective with your wildcard
# this loop selects the variable from each file and puts into file with the var name at the end
for file in $files ; do
cdo selvar,varname $file ${file%???}_varname.nc
done
# now merge into one file:
cdo merge *_varname.nc merged_file.nc
您显然需要用选择的变量名替换varname。