Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何列出文件夹中所有带.nc(netcdf)的文件,并从10个变量中提取1个变量?_R_List_Variables_Netcdf_Cdo Climate - Fatal编程技术网

R 如何列出文件夹中所有带.nc(netcdf)的文件,并从10个变量中提取1个变量?

R 如何列出文件夹中所有带.nc(netcdf)的文件,并从10个变量中提取1个变量?,r,list,variables,netcdf,cdo-climate,R,List,Variables,Netcdf,Cdo Climate,我的任务是从文件夹中获取多个类似的NetCDF(.nc)文件,并从10个变量中堆叠一个a变量 我用过: a <- list.files(path=ncpath, pattern = "nc$", full.names = TRUE) a> P>如果您只想在NETCDF文件中输出,您可以考虑在Linux中使用命令行执行此任务并使用CDO? files=$(ls *.nc) # you might want to be more selective with your wildcard

我的任务是从文件夹中获取多个类似的NetCDF
.nc
)文件,并从10个变量中堆叠一个
a
变量

我用过:

a <- list.files(path=ncpath, pattern = "nc$", full.names = TRUE)

<代码> a> P>如果您只想在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替换为所选变量的名称。

您的第二个任务不太清楚您想要什么,主要是因为我不知道“stack”是什么意思。听起来您正在进行10个赋值,或者变量“a”的长度为10,您希望从中检索单个元素。每个NetCDF文件有10个变量。在这10个变量中,我只有一个变量,比如“a”。我的任务是从多个文件中提取此变量,以便在末尾只有一个文件带有变量“a”。“堆栈、合并、连接、附加”-通过组合多个光栅层生成一个光栅文件,每个光栅层仅包含一个变量“a”“。这些文件的坐标是否相同?在这种情况下,您可以使用open_mfdataset打开它们并只保存变量“a”是的,它们有坐标…感谢您的帮助Justin和Matleo…我设法提取了…谢谢..cdo做得很好,但我无法在cygwin和WLS windows 10(ubuntu)中安装cdo…这就是为什么尝试在windows 10中安装完整的linux子系统现在非常简单的原因,在google中键入“在windows 10中安装linux”,例如,第一个链接在这里:然后只需按照步骤操作即可。安装linux后,只需打开一个窗口,键入sudo apt get install cdo,就像在仅linux平台上一样。然后你可以使用这个脚本。这绝对是一条路要走,cygwin在w10上基本上已经过时了。。。