[R] missing values in 'ncdf', integer versus byte

Albert Vernon Smith avsmith at gmail.com
Thu Feb 25 19:31:36 CET 2010


I'm working with the ncdf package, and I'm seeing a behavior which I
am unsure whether it is a bug or a feature.  I am creating a variable,
which I make with the precision of "byte" and also set a missing
value,  When I put into this variable, all my NA values are put in
properly as the missing value.  However, when I read it back, I get
the missing value rather than NA.  However, if I have a variable with
precision of "integer" it comes back as NA.

Is this the desired behavior?  If so, how might I read missing byte
values as NA?

The following shows the behavior:

--

vardim<-dim.def.ncdf("variable","units", 1:10)

variable_byte<-
var.def.ncdf("as.byte","case",dim=vardim,missval=-99,prec="byte")
variable_int<- var.def.ncdf("as.int","case",dim=vardim,missval=-99,prec="integer")


ncfilename <- "test.nc"

ncfile <- create.ncdf(ncfilename,list(variable_byte,variable_int))

array <- c(1:5,NA,7:10)

put.var.ncdf(ncfile,variable_byte,array,start=1,count=10)
put.var.ncdf(ncfile,variable_int,array,start=1,count=10)

close(ncfile)

nc <- open.ncdf(ncfile)

int_return <- get.var.ncdf(nc, "as.int", start=1, count=10)
byte_return <- get.var.ncdf(nc, "as.byte", start=1, count=10)

--

> int_return
 [1]  1  2  3  4  5 NA  7  8  9 10
> byte_return
 [1]  1  2  3  4  5 -99  7  8  9 10

Thanks,
-albert



More information about the R-help mailing list