Quantcast

comparison (1) is possible only for atomic and list types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

comparison (1) is possible only for atomic and list types

Nikki roy
Dear All,

I want to generalize a soil map from 34 levels to 8. and i am getting this
error:
Error in x[i] == "Calcaric Cambisols" :
  comparison (1) is possible only for atomic and list types
In addition: Warning message:
In is.na(x[i]) : is.na() applied to non-(list or vector) of type 'S4'

any suggestions
this is my script

soil_raster_data <- overlay(dem, mw_soil.utm)   # result is a vector with
polygon ids
soil_raster_grp <- mw_soil.utm$FAO_CLASS[soil_raster_data] # now the factor
are stored
soil_raster <- SpatialGridDataFrame(dem@grid,
as.data.frame(soil_raster_grp))
x=soil_raster

levels(x) = c(levels(x), "cambisols", "gleysols", "regosols",
 "luvisols","vertisol","planosols","lixisols","alisols","ferralsols","NA")
#using the factor
for (i in 1:length(x)){
if (is.na(x[i]))
{x[i]="NA"}
else if (x[i] == "Calcaric Cambisols" || x[i] == "Chromic Cambisols" || x[i]
== "Dystric Cambisols"|| x[i] == "Eutric Cambisols"||x[i]=="Ferralic
Cambisols"||x[i] =="Gleyic Cambisols"||x[i] =="Vertic Cambisols")
{x[i] = "cambisols"}
else if  (x[i] == "Calcaric Gleysols"  || x[i] == "Eutric Gleysols")
 {x[i] = "gleysols"}
else if (x[i] == "Calcaric Regosols" || x[i] == "Cambic Arenosols" || x[i]
== "Eutric Fluvisols"|| x[i] == "Eutric Regosols"||x[i]=="Gleyic
Arenosols"||x[i] =="Haplic Acrisols"||x[i] =="Leptosols"|| x[i] == "Mollic
Fluvisols")
{x[i] = "regosols"}
else if (x[i] == "Calcic Luvisols" || x[i] == "Chromic Luvisols" || x[i] ==
"Ferric Luvisols"|| x[i] == "Gleyic Luvisols"||x[i]=="Haplic Luvisols")
{x[i] = "luvisols"}
else if  (x[i] == "Calcic Vertisol"  || x[i] == "Eutric Vertisol")
 {x[i] = "vertisol"}
else if  (x[i] == "Eutric Planosols")
 {x[i] = "planosols"}
else if  (x[i] == "salic"  || x[i] == "fluvic")
 {x[i] = "Ferric Lixisols"}
else if  (x[i] == "Haplic Alisols"  || x[i] == "Humic Alisols")
 {x[i] = "alisols"}
else if  (x[i] == "Haplic Ferralsols"  || x[i] == "Humic Ferralsols"||x[i]
== "Rhodic Ferralsols"  || x[i] == "Xanthic Ferralsols")
 {x[i] = "ferralsols"}}
Regards,

Nikkie

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: comparison (1) is possible only for atomic and list types

Tom Gottfried
Nikki,

I'm not sure whether I understood what you are trying to do, but if you just want to replace values
in a column of a SpatialGridDataFrame, sp comes with all the methods you need. Example:

library(sp)
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
meuse.grid <- as(as(meuse.grid, "SpatialPixelsDataFrame"),"SpatialGridDataFrame")
spplot(meuse.grid[,,"soil"])

meuse.grid$soil[meuse.grid$soil==1] <- 4
meuse.grid$soil[meuse.grid$soil==2 | meuse.grid$soil==3] <- 5
spplot(meuse.grid[,,"soil"])

Hope that helps,
Tom
--
Technische Universität München
Department für Pflanzenwissenschaften
Lehrstuhl für Grünlandlehre
Alte Akademie 12
85350 Freising / Germany
Phone: ++49 (0)8161 715324
Fax:   ++49 (0)8161 713243
email: [hidden email]
http://www.wzw.tum.de/gruenland

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Loading...