[R-sig-Geo] comparison (1) is possible only for atomic and list

Tom Gottfried tom.gottfried at wzw.tum.de
Sun Feb 20 23:20:51 CET 2011


Hi Nikki,

I'm myself not an expert in dealing with factors, so my approach would 
be to coerce the factor-column to character with

yourgrid$factor_column <- as.character(yourgrid$factor_column)

then perform the substitutions as in the meuse.grid example and coerce 
back to factor if needed with

yourgrid$factor_column <- factor(yourgrid$factor_column)

Maybe somebody else on the list has a cleaner/more efficient way do deal 
with this?

regards,
Tom


Am 20.02.2011 14:57, schrieb Nikki roy:
> Hi Tom,
>
> What you said here works for numbers datatype but  my data type is factor
> (levels). i am still very new to R. Please help.
>
> library(sp)
> data(meuse.grid)# "data.frame"
> coordinates(meuse.grid)<- ~x+y
> meuse.grid<- as(as(meuse.grid,
> "SpatialPixelsDataFrame"),"SpatialGridDataFrame")#"SpatialGridDataFrame"
> spplot(meuse.grid[,,"soil"])
> meuse.grid$soil[meuse.grid$soil==1]<- NA
> meuse.grid$soil[meuse.grid$soil==2 | meuse.grid$soil==3]<- 5
> spplot(meuse.grid[,,"soil"])
> summary(meuse.grid$soil)
>
> Regards,
>
> Nikki
>
> 	[[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



More information about the R-sig-Geo mailing list