Dear R-er,
I would like format integer number as characters with leading 0 for a
fixed width, for example:
1 shoud be "01"
2 shoud be "02"
20 should be "20"
Now I use:
x <- c(1, 2, 20)
gsub(" ", "0", format(x, width=2))
But I suspect more elegant way could be done directly with format
opt
Marc Girondot via R-help writes:
> I would like format integer number as characters with leading 0 for a
> fixed width, for example:
>
> 1 shoud be "01"
> 2 shoud be "02"
> 20 should be "20"
formatC(x, width=2, flag="0")
signature.asc
Description: PGP signature
___
On Thu, Jan 04, 2018 at 09:12:12PM +0100, Marc Girondot via R-help wrote:
> Dear R-er,
>
> I would like format integer number as characters with leading 0 for a
> fixed width, for example:
>
> 1 shoud be "01"
> 2 shoud be "02"
> 20 should be "20"
>
> Now I use:
>
> x <- c(1, 2, 20)
>
> gsub("
Dear R-er,
I would like format integer number as characters with leading 0 for a
fixed width, for example:
1 shoud be "01"
2 shoud be "02"
20 should be "20"
Now I use:
x <- c(1, 2, 20)
gsub(" ", "0", format(x, width=2))
But I suspect more elegant way could be done directly with format
opt
4 matches
Mail list logo