zeroPad: Pad string with leading zeros

Description Usage Arguments Value Examples

View source: R/zeroPad.r

Description

Function to pad a string with leading zeros. Useful for parameter codes and USGS site IDs.

Usage

1
zeroPad(x, padTo)

Arguments

x

character

padTo

number Final desired length of the character

Value

x character returned with leading zeros

Examples

1
2
3
4
5
6
pCode <- '10'
correctPCode <- zeroPad(pCode,5)
pCodes <- c('100','1000','0','12345','1565465465465465')
correctPCodes <- zeroPad(pCodes,5)
pCodeNA <- c(1,2,NA)
padPCodeNA <- zeroPad(pCodeNA,4)

Example output



dataRetrieval documentation built on Sept. 14, 2021, 5:16 p.m.