Consider a character vector
test <- c('ab12','cd3','ef','gh03')
I need all elements of test
to contain 4 characters (nchar(test[i])==4
). If the actual length of the element is less than 4, the remaining places should be filled with zeroes. So, the result should look like this
> 'ab12','cd30','ef00','gh03'
My question is similar to this one. Yet, I need to work with a character vector.