r - 我如何在文件夹中列出所有带有 .nc (netcdf) 的文件并从 10 个变量中提取 1 个变量?
问题描述
我的任务是从一个文件夹中获取多个相似的NetCDF ( .nc
) 文件,并从 10 个变量中堆叠一个a
变量。
我用了:
a <- list.files(path=ncpath, pattern = "nc$", full.names = TRUE)
这让我得到了所有带有.nc
扩展名的文件。
如何进行第二项任务?
a
我想要一个文件夹中这些文件数量的这个变量并将它们堆叠起来。
解决方案
如果您只想要 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 替换为您选择的变量的名称。
推荐阅读
- javascript - Babel - 如何从 javascript 中删除 require
- python - 在 Python 数据类上使用哈希作为标识
- c++ - 为什么使用 unsigned short 会比使用 int 慢?
- reactjs - 将数据从子级传递给父级 React
- javascript - javascript中3位数字的溢出计数器
- kubernetes - 限制 prometheus 仅发现特定命名空间中的 pod
- zig - zig语言中使用var而不是const的结构定义
- excel - 无法在 vba 中使用 getElementsById 进行网页抓取
- python - 如何在没有唯一类或标识符的情况下进行网页抓取?
- javascript - Ant Design 的 Table 的动态 pageSize 属性