Learn R Programming

survSpearman (version 1.0.1)

fillUpStr: Adds characters to the head or tail of each element of the character vector.

Description

Adds characters to the head or tail of each element of the character vector to make all elements the same length.

Usage

fillUpStr(strVec, howManyToFill, where, fill)

Value

A character string with equal number of characters in each element.

Arguments

strVec

A vector of character strings.

howManyToFill

The target number of characters in each element of strVec. If howManyToFill is NULL or less than the number of characters in the longest element of strVec, then the number of characters in the longest element is used.

where

Where to place the characters: at the beginning of each element ('head', the default) or at the end of each element ('tail')

fill

What character to add. The default is a blank space.

Author

Svetlana K Eden, svetlanaeden@gmail.com

Details

The function adds characters to the head or tail of each element of the character vector, strVec, so that all elements have the same number of characters. NA values are returned unchanged. If howManyToFill is NULL or less than the number of characters in the longest element of strVec, then the number of characters in the longest element is used.

Examples

Run this code
fillUpStr(c("A", "aaa", NA, "bb", "4.5"), where="tail", howManyToFill = 4, fill = "_")
fillUpStr(c("A", "aaa", NA, "bb", "4.5"), where="tail", howManyToFill = -3, fill = "_")
fillUpStr(c("A", "aaa", NA, "bb", "4.5"), where="head", howManyToFill = -3, fill = "*")

Run the code above in your browser using DataLab