如何从R中的netCDF文件中提取变量名? [英] How to extract variable names from a netCDF file in R?
问题描述
我正在R中编写一个函数,以从netCDF文件中提取一些空气质量建模数据.我已经安装了"ncdf"软件包.
I am writing a function in R to extract some air quality modelling data from netCDF files. I have the Package "ncdf" installed.
为了允许其他用户或本人选择要从netCDF文件中提取哪些变量,我想提取该文件中所有变量的名称,以便我可以显示在一个简单列表中,而不只是
In order to allow other users or myself to choose what variables to extract from a netCDF file, I would like to extract the names of all variables in the file, so that I can present in a simple list rather than just print.ncdf()
the file to give too much information. Is there any way of doing it?
我尝试了unlist()
到ncdf对象的var
字段,但似乎它也返回了内容...
I tried unlist()
to the var
field of the ncdf object but it seemed that it returned the contents as well...
我搜索并搜索了堆栈* 溢出 *,但似乎没有找到答案,因此非常感谢您的帮助.
I googled and searched stack*overflow* but didn't seem to find an answer, so your help is very much appreciated.
非常感谢.
推荐答案
如果您的ncdf对象称为nc
,则非常简单:
If your ncdf object is called nc
, then quite simply:
names(nc$var)
以示例为例,使用下载的数据集在这里(因为您没有提供):
With an example, using the dataset downloaded here, for instance (since you didn't provide with one):
nc <- open.ncdf("20130128-ABOM-L4HRfnd-AUS-v01-fv01_0-RAMSSA_09km.nc")
names(nc$var)
[1] "analysed_sst" "analysis_error" "sea_ice_fraction" "mask"
这篇关于如何从R中的netCDF文件中提取变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!