[R-sig-Geo] as() and conversion from character to factor
MacQueen, Don
macqueen1 at llnl.gov
Thu Oct 4 20:31:40 CEST 2012
I just noticed that in the following sequence the final step to
SpatialGridDataFrame converts the character column to factor, whereas the
previous ones do not. Source the following little script, and it will
hopefully show what I'm seeing. Shouldn't this be consistent?
Thanks
-Don
require(sp)
require(maptools)
tstdf <- expand.grid(x=1:3, y=1:3)
tstdf$ch <- rep('a',nrow(tstdf))
tstsp <- tstdf
coordinates(tstsp) <- c('x','y')
proj4string(tstsp) <- CRS('+init=epsg:32610')
tstpx <- as(tstsp, "SpatialPixelsDataFrame")
tstgrd <- as(tstpx, "SpatialGridDataFrame")
print(class(tstdf$ch))
print(class(tstsp$ch))
print(class(tstpx$ch))
print(class(tstgrd$ch))
#########
I get:
> print(class(tstdf$ch))
[1] "character"
> print(class(tstsp$ch))
[1] "character"
> print(class(tstpx$ch))
[1] "character"
> print(class(tstgrd$ch))
[1] "factor"
#########
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] C
attached base packages:
[1] stats utils datasets grDevices graphics methods base
other attached packages:
[1] maptools_0.8-16 lattice_0.20-6 foreign_0.8-50 sp_1.0-0
loaded via a namespace (and not attached):
[1] grid_2.15.1 rmacq_1.1-8
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
More information about the R-sig-Geo
mailing list