[R-sig-Geo] NAs not permitted in row index

Benedikt Gräler ben.graeler at uni-muenster.de
Fri Mar 21 10:14:34 CET 2014


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 at 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 at uni-muenster.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 560 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140321/bf705a22/attachment.bin>


More information about the R-sig-Geo mailing list