[R-sig-Geo] NaN / NA values in SpatialPixelDataFrame conversion

Johannes Radinger johannesradinger at gmail.com
Thu Sep 27 11:46:24 CEST 2012


Hi,

I load a bunch of raster maps (geotiffs) and stack them to a
rasterstack called "rast".
This rasterstack can be sucessfully transformed into a
SpatialPixelsDataFrame SPDF and
afterwards into a data.frame with as.data.frame. The procedure itself
works there
is just the problem that the NA values from the SPDF are transformed
into NaNs when
I use as.data.frame(...)

Here how I load and transform my raster maps:

#### get data
rast <- stack(list.files(path="path/to/my/rastermaps", full.names=TRUE))

#convert raster to spatial pixels dataframe
rast.spdf <- as(rast, "SpatialPixelsDataFrame")
rast.df <- as.data.frame(rast,xy=TRUE,optional=FALSE)

I am not sure but is this behaviour new after an update? Is
there any setting in as.data.frame which can be used to get NAs instead
of NaNs, Or do I need to transform them in a subsequent step?

cheers,
Johannes



More information about the R-sig-Geo mailing list