DescTools (version 0.99.14)

StrAlign: Align Strings To a Specified Character

Description

Align several strings to the first occurance of a specified character.

Usage

StrAlign(x, sep = " ", ...)

Arguments

x
a character vector to be aligned.
sep
the character on whose position the strings will be aligned. Left alignment can be defined by setting sep = "\\^" and right alignment by "\\$".
...
the dots are being sent via StrPos to regexpr and can for example be used to set fix = TRUE for using plain text of the required pattern.

Value

  • a character vector

See Also

StrTrim, Format

Examples

Run this code
# align on (the first occuring) B
x <- c("ABCDMNB", "CDGHEBK", "BCI")
cbind(StrAlign(x, sep="B"))

# align to decimal point
z <- c("6.0", "6.00  ", "45.12    ")
cbind(StrAlign(z, sep="."))

# right align, the width will be the max number of characters in x
StrAlign(x, sep="\\$")

Run the code above in your browser using DataCamp Workspace