Last active
November 1, 2016 11:11
-
-
Save obrl-soil/cefe7765586c877990a95e95556c8638 to your computer and use it in GitHub Desktop.
R integer to ordinal string (1 = "1st", etc)
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
# Sometimes you just want your iterated filenames to look nice. | |
nth_fun <- function(x) { | |
x <- abs(x) | |
if (as.integer(substring(x, seq(nchar(x)), seq(nchar(x))))[nchar(x)] == 1) { | |
return(paste0(x, 'st')) | |
} else if (as.integer(substring(x, seq(nchar(x)), seq(nchar(x))))[nchar(x)] == 2) { | |
return(paste0(x, 'nd')) | |
} else if (as.integer(substring(x, seq(nchar(x)), seq(nchar(x))))[nchar(x)] == 3) { | |
return(paste0(x, 'rd')) | |
} else { | |
return(paste0(x, 'th')) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment