[R-sig-Geo] identical(coordinates)

Edzer Pebesma edzer.pebesma at uni-muenster.de
Fri Feb 10 11:00:59 CET 2012



On 02/10/2012 10:51 AM, Pinaud David wrote:
> Dear all,
> I need to convert several times sp objects from data.frame and use
> zerodist2() to match locations.
> As zerodist2() seems to use identical(), something seems strange to me:
> 
> library(sp)
> 
> xy <- data.frame(x=rnorm(4), y=rnorm(4))
> dfxy <- xy
> coordinates(xy) <- ~ x + y
> dfxy[1,1]
> coordinates(xy)[1,1]
> 
> identical(dfxy[1,1], coordinates(xy)[1,1])
>> FALSE        # I should expect TRUE!?
> coordinates(dfxy) <- ~ x + y
> identical(coordinates(dfxy)[1,1], coordinates(xy)[1,1])
>> TRUE
> 
> Why identical(dfxy[1,1], coordinates(xy)[1,1]) gives FALSE?
> 

read a bit further in ?identical, and try:

> all.equal(dfxy[1,1], coordinates(xy)[1,1])
[1] "names for current but not for target"

> (dfxy[1,1])
[1] 2.787465
> coordinates(xy)[1,1]
       x
2.787465


> Thanks,
> David
> 
> sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: i386-pc-mingw32/i386 (32-bit)
> 
> locale:
> [1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252   
> LC_MONETARY=French_France.1252 LC_NUMERIC=C
> [5] LC_TIME=French_France.1252
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> other attached packages:
>  [1] rgdal_0.7-5     trip_1.1-10     maptools_0.8-12 lattice_0.20-0 
> foreign_0.8-48  rgeos_0.1-17    stringr_0.6
>  [8] sp_0.9-93       spatstat_1.25-1 deldir_0.0-16   mgcv_1.7-12
> 
> loaded via a namespace (and not attached):
> [1] grid_2.14.1  Matrix_1.0-2 nlme_3.1-102 plyr_1.7.1   tools_2.14.1
> 
> 
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
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



More information about the R-sig-Geo mailing list