Johannes,
I cannot reproduce this. I get:

> library(raster)
Loading required package: sp
raster 2.0-12 (1-September-2012)
> f <- system.file("external/test.grd", package="raster")
> rast <- stack(f, f, f)
> rast.spdf <- as(rast, "SpatialPixelsDataFrame")
> rast.df <- as.data.frame(rast,xy=TRUE,optional=FALSE)
> head(rast.df)
       x      y test.1 test.2 test.3
1 178420 333980     NA     NA     NA
2 178460 333980     NA     NA     NA
3 178500 333980     NA     NA     NA
4 178540 333980     NA     NA     NA
5 178580 333980     NA     NA     NA
6 178620 333980     NA     NA     NA
>

And is this:
> rast.df <- as.data.frame(rast,xy=TRUE,optional=FALSE)
what you intended? Or did you mean to do:

> rast.df <- as.data.frame(rast.spdf,xy=TRUE,optional=FALSE)
> head(rast.df)
   test.1  test.2  test.3      x      y
1 633.686 633.686 633.686 181180 333740
2 712.545 712.545 712.545 181140 333700
3 654.162 654.162 654.162 181180 333700
4 604.442 604.442 604.442 181220 333700
5 857.256 857.256 857.256 181100 333660
6 755.506 755.506 755.506 181140 333660
>
>


Robert

On Thu, Sep 27, 2012 at 2:46 AM, Johannes Radinger <
johannesradinger@gmail.com> wrote:

> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

