zeroPad: Pad string with leading zeros

View source: R/zeroPad.R

zeroPadR Documentation

Pad string with leading zeros

Description

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

Usage

zeroPad(x, padTo)

Arguments

x

character

padTo

number Final desired length of the character

Value

x character returned with leading zeros

Examples

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)

dataRetrieval documentation built on Oct. 5, 2023, 5:09 p.m.