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.
add_mid_year_groups(data, year_group = year_group, into = "year", sep = "-", offset = NULL)
data | A data frame |
---|---|
year_group | The unquoted column containing the |
into | Character name of the column that will contain the mid year
exctracted from |
sep | Characters separating years in |
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
|
Other year processors: complete_year_groups
,
separate_year_groups
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()#> Warning: `year` already exists in data#> # A tibble: 7 x 1 #> year #> <chr> #> 1 1981-1985 #> 2 1986-1990 #> 3 1991-1995 #> 4 1996-2000 #> 5 2001-2005 #> 6 2006-2010 #> 7 2011-2015