I have a numeric vector with a sequence of years, which might be continuous or can have multiple breaks in between:
years <- c(1990:1994, 1996, 1997, 1999:2002)
years
# 1990 1991 1992 1993 1994 1996 1997 1999 2000 2001 2002
How would I transform this vector to a single character string that describes the ranges of years covered by the vector? Continuous years should be grouped together with a dash, while gaps can be separated with commas. Desired output:
# "1990-1994, 1996-1997, 1999-2002"