Learn R Programming

mmap (version 0.6-19)

make.fixedwidth: Convert Character Vectors From Variable To Constant Width

Description

Utility function to convert a vector of character strings to one where each element has exactly ‘width’-bytes.

Usage

make.fixedwidth(x, width = NA, justify = c("left", "right"))

Value

A character vector where each element is of fixed-width.

Arguments

x

A character vector.

width

Maximum width of each element. width=NA (default) will expand each element to the width required to contain the largest element of x without loss of information.

justify

How should the results be padded? ‘left’ will add spacing to the right of shorter elements in the vector (left-justified), ‘right’ will do the opposite.

Author

Jeffrey A. Ryan

Details

The current implementation of mmap only handles fixed-width strings (nul-terminated). To simplify conversion of (potentially) variable-width strings in a character vector, all elements will be padded to the length of the longest string in the vector or set to length width if specified.

All new elements will be left or right justified based on the justify argument.

Examples

Run this code
month.name
make.fixedwidth(month.name)

Run the code above in your browser using DataLab