Skip to content

Instantly share code, notes, and snippets.

@randrescastaneda
Created July 20, 2020 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randrescastaneda/9d89ee90fb4e62c293c26d70a6334652 to your computer and use it in GitHub Desktop.
Save randrescastaneda/9d89ee90fb4e62c293c26d70a6334652 to your computer and use it in GitHub Desktop.
Assign ordinal label to numbers, based on this post https://stackoverflow.com/questions/40039903/r-add-th-rd-and-nd-to-dates
ord_nums <- function(n){
ord <- ifelse(n %in% c(11,12,13), "th",
ifelse(
n %% 10 == 1, 'st',
ifelse(
n %% 10 == 2, 'nd',
ifelse(
n %% 10 == 3 , 'rd', "th"
)
)
)
)
return(paste0(n, ord))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment