Skip to content

drop layer/band from SpatialGridDataFrame

5 messages · Michael Sumner, Andy Bunn, Matthew Landis

#
I have a SpatialGridDataFrame with 325 variables in the @ data slot. I want to drop the first layer. Seems simple enough. Any help? Thanks, Andy
Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots
  ..@ data       :'data.frame':	8060 obs. of  325 variables:
  .. ..$ values: num [1:8060] 127.5 31.9 127.5 127.5 231.1 ...
  .. ..$ values: num [1:8060] 127.5 31.9 127.5 127.5 231.1 ...
  .. and so on
#
Do you mean "layer" as in the first column in the data.frame?

Does this do what you want?  The negative index means "everything but
these indexes".

monthly.sp <- monthly.sp[,-1]
On Tue, Aug 10, 2010 at 12:40 PM, Andy Bunn <Andy.Bunn at wwu.edu> wrote:

  
    
#
I was a bit hasty. The SpatialGridDataFrame contains 325 separate grids each with 155 cols and 52 rows. E.g., if it were an array I'd think it would have dimensions of 52, 155, 325 and I'd want to do something like: monthly.sp[,,-1]. When I'm done I want the object to have 324 variables with 8060 obs and keep the cells.dim at 155 by 52.
#
Andy - how about these two options

monthly.sp at data <- monthly.sp at data[-1,]

or (cheating with the help of raster package)

monthly.stack <- as(monthly.sp, 'RasterStack')
monthly.stack <- dropLayer(monthly.stack, 1)
monthly.sp <- as(monthly.stack, 'SpatialGridDataFrame')

Apologies if these are nonsense - I don't have time to actually test 
these out on a toy example at the moment.

Matt
On 8/10/2010 3:02 PM, Andy Bunn wrote:

  
    
#
Great. Thanks! Done.