I am trying to pad each element of a vector with "0", such that the maximum width is 3
Example:
- 0 becomes 000
- 12 becomes 012
- 100 stays 100
Here is the code
myvector <- c("2", "3", "33", "90", "120")
newvector <- lapply(myvector,formatC(width=3, format="s", flag="0"))
And when I use lapply, I get error
Error in formatC(width = 3, format = "s", flag = "0") :
argument "x" is missing, with no default
Which makes no sense because I am using it in lapply
, and the first argument of lapply
is myvector
.