[R] Assigning a function to the 'times' argument of rep()

Berend Hasselman bhh at xs4all.nl
Mon Feb 13 06:37:26 CET 2012


On 13-02-2012, at 04:56, z2.0 wrote:

> Question: 
> 
> I'm trying to use paste() with rep() to reformat a series of values as zip
> codes. e.g., if column 1 looks like:
> 
> 52775
> 83111
> 99240
> 4289
> 112
> 57701
> 20001
> 
> I want rows 4 and 5 to read,
> 
> "04289"
> "00112"

This might help

x <- c(52775, 83111, 99240, 4289, 112, 57701, 20001)

> formatC(x,format="d", flag="0", width=5)
[1] "52775" "83111" "99240" "04289" "00112" "57701" "20001"

Berend



More information about the R-help mailing list