count number of missing values in netcdf file - R

主宰稳场 提交于 2019-12-13 18:15:50

问题


Is there a quick way to know how many missing values are in a netcdf file? Possibly using R.

Currently I have to

hum<-nc_open("rhum.sig995.2008.nc")
rhum<-ncvar_get(hum, "rhum")

then manually look up the missing value by typing 'hum' and copy it into this operation

sum(abs(rhum - 9.96920996838687e+36) < -9.96920996838687e+36)

Is there a more direct way, especially if I have to work with hundreds of files? I would like to avoid copying and pasting the missing value, and also I am not sure with what kind of precision the number should be handled.


回答1:


My suggestion is to use the excellent raster package:

install.packages(raster)
library(raster)

r <- raster("rhum.sig995.2008.nc", var="rhum")

NAnum <- summary(r)[6]



回答2:


The total number of missing data points for variable names "var" can be stored in a new additional variable using

ncap2 -s "nmiss=number_miss(var)" in.nc out.nc

or

ncap2 -s "nmiss=var.number_miss()" in.nc out.nc

If your data has a time dimension and you want to see the total number of missing points summed over the space dimensions, then you can see this with

cdo info in.nc


来源:https://stackoverflow.com/questions/29948782/count-number-of-missing-values-in-netcdf-file-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!