Learn R Programming

SeaVal (version 1.1.1)

add_tercile_cat: Add a tercile-category column to a data table

Description

Given a data table with multiple years of data, this function derives the tercile category per year. It first derives terciles for the data and then returns, for each row, a -1 if the data falls into the lowest tercile, 0 if it falls between 1st and second tercile, and +1 if it falls above the third tercile. Allows grouping by levels (e.g. months and location-coordinates): Tercile categories are derived separately for each level.

Usage

add_tercile_cat(
  dt,
  datacol = NULL,
  years = NULL,
  by = setdiff(dimvars(dt), c("year", "member"))
)

Value

The provided data table with an extra column tercile_cat

Arguments

dt

the data table.

datacol

Name of the column where the data is stored. If NULL, the function guesses.

years

Optional, if provided only these years are used for establishing climatology terciles.

by

names of columns to group by.

Examples

Run this code
# \donttest{
dt = add_tercile_cat(chirps_monthly)
# }

Run the code above in your browser using DataLab