Silly me. Yes. There were 3 NAs in gwno that I had missed.
pgtest <- pgcell1[pgcell1$gwno==385 & !is.na(pgcell1$gwno),]  works fint

Thanks.

Andreas


2014-03-21 10:14 GMT+01:00 Benedikt Gräler <ben.graeler@uni-muenster.de>:

> Dear Andreas,
>
> I would presume that your variable "gwno" contains NAs and the simple
> comparison by "pgcell1$gwno==385" returns a vector of TRUE, FALSE and NA
> (See the example below.). Most likely you want to drop these "empty"
> locations by setting the NAs in the boolean vector as well to FALSE.
>
> HTH,
>
>  Ben
>
> library(sp)
> data(meuse)
>
> coordinates(meuse) <- ~x+y
> # still works
> meuse[meuse$ffreq == 2,]
>
> # set some values to NA
> meuse[meuse$ffreq == 3,] <- NA
>
> # This does not work any more
> meuse[meuse$ffreq == 2,]
>
> # But subset still does the job
> subset(meuse, ffreq == 2)
>
> # This now has many NAs ("incomparables")
> meuse$ffreq == 2
>
>
> On 21.03.2014 09:44, Andreas Forø Tollefsen wrote:
> > Dear list,
> >
> > I seem to have a problem with subsetting a SpatialPolygonsDataFrame. If I
> > remember correctly, I have subsetted the spdf before using the first
> > syntax. However, this does not seem to work.
> > Any idea why?
> >
> >
> >> pgtest <- pgcell1[pgcell1$gwno==385,]
> > Error in pgcell1[pgcell1$gwno == 385, ] : NAs not permitted in row index
> >> pgtest <- subset(pgcell1, gwno==385)
> > This works.
> >
> > Thanks!
> >
> > Andreas
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> --
> Benedikt Gräler
>
> ifgi - Institute for Geoinformatics
> University of Muenster
>
> http://ifgi.uni-muenster.de/graeler
>
> Phone: +49 251 83-33082
> Mail: ben.graeler@uni-muenster.de
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>

	[[alternative HTML version deleted]]

