Learn R Programming

fame (version 1.13)

pad.string: Pad strings to a particular length

Description

Pads a collection of strings to a desired length to either the left or right with a specified character.

Usage

pad.string(x, len = max(nchar(x)), padchar = " ", right = T)

Arguments

x
character object
len
desired length of the returned strings
padchar
a single-character string.
right
if TRUE (the default), the strings in x are padded to the right, else they are padded to the left.

Value

  • an object like x, but with the strings padded out to the desired length. Strings in x that are already len or more characters long are unaffected by the function.

See Also

format

Examples

Run this code
pad.string(c("aaa", "bbbbbb", "ccccccccccc"), len = 7, padchar = "X")

Run the code above in your browser using DataLab