prettify_range | R Documentation |
Usually for plotting or reports one needs to print the range of a datasets. This function prints a nice range of dates or numbers easily
prettify_range(x, y = NULL, sep = "–")
x, y |
column with the number/dates/years/etc. If y is NULL the range is determined by the minimum and maximum value in x. If y is not NULL the beginning of the range is determined by the minimum of x and the end of the range by the maximum of y |
sep |
separator between the range |
a character with the range
# Range of a numeric vector
prettify_range(1:100)
# Changing the default separator
prettify_range(1:100, sep = " to ")
# Range using two numbers
prettify_range(1, 100)
# When two vectors are provided the minimum of the first and the maximum of the
# second is returned
tibble::tibble(period_start = 2010:2020,
period_end = 2020:2030) %>%
dplyr::mutate(pretty_range = prettify_range(period_start, period_end))
# Also work with dates
seq(Sys.Date(), Sys.Date() + 100, length.out = 100) %>%
prettify_range(sep = " and ") %>%
paste("between", .)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.