Skip to content

Instantly share code, notes, and snippets.

@dudash
Last active August 29, 2015 14:04
Show Gist options
  • Save dudash/7638ac9706da6e4610f7 to your computer and use it in GitHub Desktop.
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
# \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")
}
@tache
Copy link

tache commented Jul 22, 2014

id = 1:332
fixedIDs <- sprintf("%03s", id)

@dudash
Copy link
Author

dudash commented Jul 22, 2014

I see what you are getting at, good point, UPDATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment