R/nb-complete-graph.R

Defines functions st_complete_nb

Documented in st_complete_nb

#' Create Neighbors as Complete Graph
#'
#' Create a neighbors list where every element is related to every other element.
#' This creates a complete graph.
#'
#' @param n_elements the number of observations to create a neighbors list for
#' @inheritParams st_block_nb
#' @export
#' @returns
#' A neighbors list representing a complete graph.
#' @examples
#' st_complete_nb(5)
st_complete_nb <- function(n_elements, diag = FALSE) {
  res <- lapply(1:n_elements, function(x) 1:n_elements)
  attr(res, "self.included") <- TRUE

  if (!diag) res <- remove_self(res)
  class_modify(res, "nb")
}

Try the sfdep package in your browser

Any scripts or data that you put into this service are public.

sfdep documentation built on Jan. 11, 2023, 9:08 a.m.