1

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.

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Or use freq(r, value=NA)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.