[R-sig-Geo] identical(coordinates)

Roger Bivand Roger.Bivand at nhh.no
Fri Feb 10 11:00:20 CET 2012


On Fri, 10 Feb 2012, 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?

str(coordinates(xy)[1,1]) shows that it is named, so:

> identical(dfxy[1,1,drop=TRUE], unname(coordinates(xy)[1,1]))
[1] TRUE

Roger

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

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list