[R-sig-Geo] Accessing the ids of neighbours in spdep
kmb56 at berkeley.edu
Mon Sep 29 22:10:50 CEST 2014
This last one was what I was after:
lapply(xx, function(x) paste(attr(xx, "region.id")[x], collapse = ", "))
Thanks so much!
On Mon, Sep 29, 2014 at 2:53 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Mon, 29 Sep 2014, Frede Aakmann Tøgersen wrote:
>> I'm not really sure I understand you but perhaps something like this:
>> lapply(xx, paste, collapse = ", ")
> Yes, this is the closest we can get without more input from Kenny.
> This gives the 1-base integer indices in a list of single element
> character vectors. If the output should be a character vector with the same
> number of elements as the input:
> lapply(xx, as.character)
> will do it. But the IDs of the underlying entities (could be FIPS, NUTS3,
> whatever) are in attr(xx, "region.id"), so to get those:
> lapply(xx, function(x) attr(xx, "region.id")[x])
> is needed, or if a list of single element character vectors is required:
> lapply(xx, function(x) paste(attr(xx, "region.id")[x], collapse = ", "))
> Here the IDs are 0-based rather than 1-based, but the attr(xx, "region.id")
> values are arbitrary - they are taken from row.names() of the spatial
> object unless given as an argument to functions creating the "nb" object.
> Hope this clarifies,
>> Yours sincerely / Med venlig hilsen
>> Frede Aakmann Tøgersen
>> Specialist, M.Sc., Ph.D.
>> Plant Performance & Modeling
>> Technology & Service Solutions
>> T +45 9730 5135
>> M +45 2547 6050
>> frtog at vestas.com
>> Company reg. name: Vestas Wind Systems A/S
>> This e-mail is subject to our e-mail disclaimer statement.
>> Please refer to www.vestas.com/legal/notice
>> If you have received this e-mail in error please contact the sender.
>> -----Original Message-----
>>> From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-
>>> project.org] On Behalf Of Kenny Bell
>>> Sent: 29. september 2014 00:10
>>> To: r-sig-geo at r-project.org
>>> Subject: [R-sig-Geo] Accessing the ids of neighbours in spdep
>>> I am trying to get an actual list of neighbour ids out of an nb object.
>>> example, I have
>>> xx <- poly2nb(columbus)
>>> What would be my command to get the list of neighbours as a list of
>>> character vectors?
>>> Thanks so much for any help,
>>> [[alternative HTML version deleted]]
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
Email: kmb56 at berkeley.edu
Phone: (510) 612-3375
Department of Agricultural & Resource Economics
University of California, Berkeley
Graduate Student Researcher
Energy Biosciences Institute
[[alternative HTML version deleted]]
More information about the R-sig-Geo