add_mid_year_groups: Add Mid-Year of Year Group

Description Usage Arguments See Also Examples

View source: R/year.R

Description

Adds a new column containing the midpoint year of the range given in the column indicated by the year_group argument, in a new column named according to the into argument. The year column is assumed to contain a min year and a max year, separated by sep. The midpoint is calculated as floor((year_max - year_min) / 2) unless offset is explicitly provided.

Usage

1
2
add_mid_year_groups(data, year_group = year_group, into = "year",
  sep = "-", offset = NULL)

Arguments

data

A data frame

year_group

The unquoted column containing the year_group.

into

Character name of the column that will contain the mid year exctracted from year_group.

sep

Characters separating years in year. Whitespace on either side of sep will be automatically removed. Passed to tidyr::separate().

offset

If supplied, the number of years to be added to the lower bound of the year group to calculate the mid-year value. By default uses floor((year_max - year_min) / 2).

See Also

Other year processors: complete_year_groups, separate_year_groups

Examples

1
2
3
4
5
year_groups <- c("1981-1985", "1986-1990", "1991-1995", "1996-2000",
                 "2001-2005", "2006-2010", "2011-2015")

dplyr::tibble(year = year_groups) %>%
  add_mid_year_groups()

GerkeLab/fcds documentation built on July 30, 2020, 7:04 p.m.