add_tercile_cat {SeaVal}R Documentation

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"))
)

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.

Value

The provided data table with an extra column tercile_cat

Examples


dt = add_tercile_cat(chirps_monthly)


[Package SeaVal version 1.1.1 Index]