Created
July 20, 2020 17:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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