compute_total: Compute totals for the number of entities (individuals,...

View source: R/compute_total.R

compute_totalR Documentation

Compute totals for the number of entities (individuals, devices...).

Description

Compute totals for the number of entities (individuals, devices...).

Usage

compute_total(individuals.sf, what, by, by_values = NULL)

Arguments

individuals.sf

sf object with data about the individuals.

what

character vector denoting what total to compute. Possible values are 'individuals', 'individuals_dev0', 'individuals_dev1', 'individuals_dev2' , 'devices'.

by

character vector denoting the variable names to group the computation.

by_values

named list (names given by variable by) with the values of each by variable. The default value is NULL, in which case values are taken from individuals.sf.

Details

Return a data.table with the totals by group. Notice than when not specifying the values of the by argument, missing values are not included in the final data.table, i.e. amounting to implicit value 0. Otherwise, all values of the by variable will be included with the corresponding increase of computational overhead to explicitly include zero values.

Examples

filename_map <- c(
  xml = system.file("extdata/input_files", "map.xml", package = "simutils"),
  xsd = ""
)

filename_network <- c(
  csv = system.file("extdata/output_files/antennas.csv", package = "simutils"),
  xml = system.file("extdata/metadata/output_files/antennas_dict.xml", package = "simutils")
)

filename_signal <- c(
  csv = system.file("extdata/output_files/SignalMeasure_MNO1.csv", package = "simutils"),
  xml = system.file("extdata/metadata/output_files/SignalMeasure_dict.xml", package = "simutils")
)

filename_coverage <- c(
  csv = system.file("extdata/output_files", "AntennaCells_MNO1.csv", package = "simutils"),
  xml = system.file("extdata/metadata/output_files/AntennaCells_dict.xml", package = "simutils")
)

filename_events <- c(
  csv = system.file("extdata/output_files/AntennaInfo_MNO_MNO1.csv", package = "simutils"),
  xml = system.file("extdata/metadata/output_files/events_dict.xml", package = "simutils")
)

filename_grid <- c(
  csv = system.file("extdata/output_files/grid.csv", package = "simutils"),
  xml = system.file("extdata/metadata/output_files/grid_dict.xml", package = "simutils")
)

filename_individ <- c(
  csv = system.file("extdata/output_files/persons.csv", package = "simutils"),
  xml = system.file("extdata/metadata/output_files/persons_dict.xml", package = "simutils")
)

filenames <- list(
  map                = filename_map,
  network_parameters = filename_network,
  signal             = filename_signal,
  events             = filename_events,
  coverage_cells     = filename_coverage,
  grid               = filename_grid,
  individuals        = filename_individ
)

simData <- simutils::read_simData(filenames, crs = 2062)

# Counting individuals by subregion and time
compute_total(simData$individuals, "individuals", by = c("t", "Subregion_long"))

# Counting individuals by subregion and time with 0 devices
compute_total(simData$individuals, "individuals_dev0", by = c("t", "Subregion_long"))[]

# Counting individuals by subregion and time with 1 device
compute_total(simData$individuals, "individuals_dev1", by = c("t", "Subregion_long"))[]

# Counting individuals by subregion and time with 2 devices
compute_total(simData$individuals, "individuals_dev2", by = c("t", "Subregion_long"))[]

# Counting devices by subregion and time
compute_total(simData$individuals, "devices", by = c("t", "Subregion_long"))[]

# Counting multiple totals by subregion and time
totals <- c("individuals", "individuals_dev0", "devices")
compute_total(simData$individuals, totals, by = c("t", "Subregion_long"))[]


# Counting devices by tile and time
compute_total(simData$individuals, "devices",
  by = c("t", "Tile ID"),
  by_values = list(`Tile ID` = 0:1599)
)[]


bogdanoancea/simutils documentation built on April 4, 2022, 2:58 p.m.