Question

I have a vector of calendar days such as vec_day

vec_day<- c(8,14,365,9)
vec_day
[1]   8  14 365   9

I would like to transform this to vec_day2

vec_day2     
[1] "008" "014" "365" "009"     

It can be either a string or a vector

Was it helpful?

Solution

vec_day2 <- sprintf("%03d", vec_day)
[1] "008" "014" "365" "009"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top