aggregate_category: Aggregate count by category

View source: R/dataFunctions.R

aggregate_categoryR Documentation

Aggregate count by category

Description

Get count (or frequency) of number of entries per taxon for each category. The return will be a matrix with rows equal to your taxa and columns all possible categories for the focal column, with entries being the number / frequency of records for that taxon for that category

Usage

aggregate_category(
  locations,
  focal = "realm",
  group_by = "taxon",
  return_frequency = FALSE
)

Arguments

locations

Data.frame of locations (i.e., from locality_add_habitat_biome)

focal

Column name to aggregate data over.

group_by

What column name to use for grouping

return_frequency

Boolean; if TRUE, give frequency, not counts

Value

A matrix of counts or frequencies

Examples

locations <- spocc_taxon_query("Bubo", limit=500)
locations <- locality_clean(locations)
locations <- locality_add_habitat_biome(locations)
biome_counts <- aggregate_category(locations, focal="biome", group_by="taxon")
print(head(biome_counts))
realm_frequencies <- aggregate_category(locations, focal="realm", group_by="taxon", return_frequency=TRUE)
print(head(realm_frequencies))

bomeara/chapter2 documentation built on July 22, 2023, 3:19 a.m.