Last active
August 29, 2015 14:04
-
-
Save dudash/7638ac9706da6e4610f7 to your computer and use it in GitHub Desktop.
R code to convert a vector of ints to common width strings by prepending 0's
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
# \fn | |
# \brief Get common width strings from a list of numbers | |
# \param 'numbers' is an integer vector of numbers | |
# \return A vector of strings normalized to the same width | |
# | |
# Example: | |
# inputof: 5,6,7,8,9,10,11 | |
# outputs: 05,06,07,08,09,10,11 | |
toStringVectorPrependZeros <- function(numbers) | |
{ | |
width <- nchar(toString(max(numbers))) | |
vec <- formatC(numbers, width=width, flag="0") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see what you are getting at, good point, UPDATED