cell2nb                package:spdep                R Documentation

_G_e_n_e_r_a_t_e _n_e_i_g_h_b_o_u_r_s _l_i_s_t _f_o_r _g_r_i_d _c_e_l_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     The function generates a list of neighbours for a grid of cells.
     Helper functions are used to convert to and from the vector
     indices for row and  column grid positions, and rook (shared edge)
     or queen (shared edge or  vertex) neighbour definitions are
     applied by type. If torus is TRUE, the  grid is mapped onto a
     torus, removing edge effects.

_U_s_a_g_e:

     cell2nb(nrow, ncol, type="rook", torus=FALSE)
     mrc2vi(rowcol, nrow, ncol)
     rookcell(rowcol, nrow, ncol, torus=FALSE, rmin=1, cmin=1)
     queencell(rowcol, nrow, ncol, torus=FALSE, rmin=1, cmin=1)
     vi2mrc(i, nrow, ncol)

_A_r_g_u_m_e_n_t_s:

    nrow: number of rows in the grid

    ncol: number of columns in the grid

    type: rook or queen

   torus: map grid onto torus

  rowcol: matrix with two columns of row, column indices

       i: vector of vector indices corresponding to rowcol

    rmin: lowest row index

    cmin: lowset column index

_V_a_l_u_e:

     The function returns an object of class 'nb' with a list of
     integer vectors containing neighbour region number ids.

_A_u_t_h_o_r(_s):

     Roger Bivand Roger.Bivand@nhh.no

_S_e_e _A_l_s_o:

     'summary.nb'

_E_x_a_m_p_l_e_s:

     nb7rt <- cell2nb(7, 7)
     summary(nb7rt)
     xyc <- attr(nb7rt, "region.id")
     xy <- matrix(as.integer(unlist(strsplit(xyc, ":"))), ncol=2, byrow=TRUE)
     plot(nb7rt, xy)
     nb7rt <- cell2nb(7, 7, torus=TRUE)
     summary(nb7rt)

