[R-sig-Geo] as() and conversion from character to factor
MacQueen, Don
macqueen1 at llnl.gov
Mon Oct 22 21:53:12 CEST 2012
Thank you.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 10/7/12 8:26 AM, "Edzer Pebesma" <edzer.pebesma at uni-muenster.de> wrote:
>For now, you should be able to prevent this by starting your script with
>an
>
>options(stringsAsFactors = FALSE)
>
>but in future releases, sp will not do this conversion.
>
>Thanks,
>
>On 10/04/2012 09:31 PM, MacQueen, Don wrote:
>> 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
>>
>>
>>
>>
>>
>>
>>
>>
>
>--
>Edzer Pebesma
>Institute for Geoinformatics (ifgi), University of Münster
>Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
>8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
>http://www.52north.org/geostatistics e.pebesma at wwu.de
>
>_______________________________________________
>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