[R-sig-Geo] subsetting a SpatialGridDataFrame image.SpatialGridDataFrame

Roger Bivand Roger.Bivand at nhh.no
Fri Aug 13 14:31:06 CEST 2010


On Fri, 13 Aug 2010, Patrick Giraudoux wrote:

>
> Hi,
>
> I am trying to subset a SpatialGridDataFrame object as following:
>
> idx<-ChinaTempUTM47 at data[,1]>10 # select elements of column1  whose values 
> are > 10
> idx[is.na(idx)]<-FALSE # make a vector of class "logical" (replacing NA by 
> FALSE)
>
> and this gives:
>
> ChinaTempUTM47[idx,]
> Error in ChinaTempUTM47[idx, ] : (subscript) logical subscript too long
>
> However,
>
>> length(idx)
> [1] 13536
>> nrow(ChinaTempUTM47 at data)
> [1] 13536
>

This was discussed in:

https://stat.ethz.ch/pipermail/r-sig-geo/2010-August/008973.html

Use one of the solutions suggested there, and note that the "[" method for 
SpatialGridDataFrame takes [ row, col, band, ...], like an array but not 
like a data.frame; see ?"SpatialGridDataFrame-class". You could also 
coerce to SpatialPixelsDataFrame, which then behaves like a data.frame, 
not an array.

Hope this helps,

Roger

>
> So, I canot sort out what happens.
>
> Any hint welcome
>
> Patrick
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list