completar_territorios: Complete territorial and temporal combinations

View source: R/geography.R

completar_territoriosR Documentation

Complete territorial and temporal combinations

Description

Adds absent territory-period rows while protecting existing observations. By default the territorial universe is the set observed in 'dados'. Supply 'uf' to complete all current territories in one or more states, or 'territorios' for an explicit universe. If 'periodos' is omitted, the distinct periods observed in the data are used.

Usage

completar_territorios(
  dados,
  codigo,
  periodo = NULL,
  grupo = NULL,
  nivel = c("municipio", "uf", "regiao"),
  territorios = NULL,
  uf = NULL,
  periodos = NULL,
  preencher = list(),
  adicionar = TRUE
)

Arguments

dados

A data frame.

codigo

Name of the territorial code column.

periodo

Optional name of the period column.

grupo

Optional names of grouping columns whose observed combinations must be completed separately.

nivel

Territorial level: '"municipio"', '"uf"' or '"regiao"'.

territorios

Optional vector defining the territorial universe.

uf

Optional state selector used to define the current territorial universe. For municipality data it includes every current municipality in the selected states.

periodos

Optional vector defining the period universe.

preencher

Named list of scalar values used only for rows created by the function, for example 'list(casos = 0)'.

adicionar

Whether to append current territorial attributes with [adicionar_territorio()].

Value

A data frame ordered by groups, territory and period.

Examples

dados <- data.frame(
  codmun = c("500270", "500270", "500370"),
  ano = c(2023, 2025, 2023),
  casos = c(10, 12, 5)
)
completar_territorios(
  dados, "codmun", "ano",
  periodos = 2023:2025,
  preencher = list(casos = 0)
)

datasus documentation built on Oct. 7, 2026, 1:07 a.m.