Need to convert netcdf fill values from Matlab to R

88 views Asked by At

I have this piece of code in Matlab which I believe is replacing netcdf fill values with Matlab fill values. How do I convert this code into R ? I am using netcdf4

inp.COAST_RLON.data ( inp.COAST_RLON.data< -900 ) = NaN;
inp.COAST_RLAT.data ( inp.COAST_RLAT.data< -900 ) = NaN;
1

There are 1 answers

0
Spacedman On BEST ANSWER

If you have an R vector, matrix, or array and wish to replace values matching a criterion with another value, you do:

 foo[criterion]=replacement

So your criterion is foo < -900 and your replacement is NA.

So whatever you read from netcdf files as vectors, matrices, or arrays can be fixed:

 rlon <- ncvar_get(ncin,"COAST_RLON")
 rlon[rlon < -900] = NA

I'm not totally familiar with what ncvar_get returns but I think its a vector, matrix, or array.