Separates a column containing year groups, such as "1983-1985", into two separate columns named year_min and year_max by default.

separate_year_groups(data, year_group = year_group,
  into = c("year_min", "year_max"), sep = "-")

Arguments

data

A data frame

year_group

The unquoted column containing the year_group.

into

The names of the min year and max year columns (respectively) into which the minimum and maximum year from year_group are added. Set to NULL to use the year_group column name as a prefix with _min and _max appended.

sep

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

See also

Examples

year_groups <- c("1981-1985", "1986-1990", "1991-1995", "1996-2000", "2001-2005", "2006-2010", "2011-2015") dplyr::tibble(year_group = year_groups) %>% separate_year_groups()
#> # A tibble: 7 x 3 #> year_group year_min year_max #> <chr> <chr> <chr> #> 1 1981-1985 1981 1985 #> 2 1986-1990 1986 1990 #> 3 1991-1995 1991 1995 #> 4 1996-2000 1996 2000 #> 5 2001-2005 2001 2005 #> 6 2006-2010 2006 2010 #> 7 2011-2015 2011 2015