[R-sig-Geo] Subsetting a SpatialPixels object: different behaviour with different versions of R and sp

Elena Couce Molina E.Couce.07 at bristol.ac.uk
Fri Jul 22 13:14:41 CEST 2011


Dear all,

I have a code written under R version 2.10.1 and sp package 0.9-65  
that gives different results when it is run in a colleague's computer  
with a newer version of R and sp (R version 2.13.1 and sp version  
0.9-83). The code is simply the selection of a subset of a  
SpatialPixelsDataFrame object.

In my computer, the code behaves as I would expect:

 > summary(ModelData)

Object of class SpatialPixelsDataFrame
Coordinates:
   min max
x -180 180
y  -90  90
Is projected: FALSE
proj4string : [+proj=longlat +ellps=WGS84]
Number of points: 64800
Grid attributes:
  cellcentre.offset cellsize cells.dim
x            -179.5        1       360
y             -89.5        1       180
Data attributes:
   Temp_mean              Arag
  Min.   :   -1.884   Min.   :    1.259
  1st Qu.:    1.703   1st Qu.:    1.816
  Median :   16.251   Median :    2.814
  Mean   :   14.017   Mean   :    2.756
  3rd Qu.:   24.365   3rd Qu.:    3.599
  Max.   :   31.396   Max.   :    4.504
  NA's   :23457.000   NA's   :23734.000

# Selecting a subset:
lat_ok <- intersect(which(coordinates(ModelData)[, 2] <=
60),which(coordinates(ModelData)[, 2] >= -60))
ModelData_new <- ModelData[lat_ok,]

 > summary(ModelData_new)

Object of class SpatialPixelsDataFrame
Coordinates:
   min max
x -180 180
y  -60  60
Is projected: FALSE
proj4string : [+proj=longlat +ellps=WGS84]
Number of points: 43200
Grid attributes:
  cellcentre.offset cellsize cells.dim
x            -179.5        1       360
y             -59.5        1       120
Data attributes:
   Temp_mean               Arag
  Min.   :   -0.4695   Min.   :    1.380
  1st Qu.:   12.6654   1st Qu.:    2.539
  Median :   21.0919   Median :    3.220
  Mean   :   18.8588   Mean   :    3.107
  3rd Qu.:   25.4367   3rd Qu.:    3.746
  Max.   :   31.3959   Max.   :    4.504
  NA's   :11964.0000   NA's   :11968.000


In my friend's computer, although the bounding box of subsetted object  
changes, the "Grid attributes" dont:

 > summary(ModelData)

Object of class SpatialPixelsDataFrame
Coordinates:
  min max
x -180 180
y  -90  90
Is projected: FALSE
proj4string : [+proj=longlat +ellps=WGS84]
Number of points: 64800
Grid attributes:
  cellcentre.offset cellsize cells.dim
x            -179.5        1       360
y             -89.5        1       180
Data attributes:
  Temp_mean              Arag
  Min.   :   -1.884   Min.   :    1.259
  1st Qu.:    1.703   1st Qu.:    1.816
  Median :   16.251   Median :    2.814
  Mean   :   14.017   Mean   :    2.756
  3rd Qu.:   24.365   3rd Qu.:    3.599
  Max.   :   31.396   Max.   :    4.504
  NA's   :23457.000   NA's   :23734.000

 > # Selecting a subset:
 > lat_ok <- intersect(which(coordinates(ModelData)[, 2] <=
60),which(coordinates(ModelData)[, 2] >= -60))
 > ModelData_new <- ModelData[lat_ok,]

 > summary(ModelData_new)

Object of class SpatialPixelsDataFrame
Coordinates:
  min max
x -180 180
y  -60  60
Is projected: FALSE
proj4string : [+proj=longlat +ellps=WGS84]
Number of points: 43200
Grid attributes:
  cellcentre.offset cellsize cells.dim
x            -179.5        1       360
y             -89.5        1       180
Data attributes:
  Temp_mean               Arag
  Min.   :   -0.4695   Min.   :    1.380
  1st Qu.:   12.6654   1st Qu.:    2.539
  Median :   21.0919   Median :    3.220
  Mean   :   18.8588   Mean   :    3.107
  3rd Qu.:   25.4367   3rd Qu.:    3.746
  Max.   :   31.3959   Max.   :    4.504
  NA's   :11964.0000   NA's   :11968.000


Is this a bug? This creates problems later in the code when we try to  
convert the object into SpatialGrid class and get different bounding  
boxes...

Thanks for your help,
Elena


Details of the versions of R and installed packages we are using:

1) In my computer:

 > sessionInfo()

R version 2.10.1 (2009-12-14)
x86_64-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/
en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_0.6-24 sp_0.9-65

loaded via a namespace (and not attached):
[1] grid_2.10.1    lattice_0.18-3


2) For my friend's computer:

 > sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_0.6-33 sp_0.9-83

loaded via a namespace (and not attached):
[1] grid_2.13.1     lattice_0.19-30



More information about the R-sig-Geo mailing list