fillUpStr {survSpearman}R Documentation

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)

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.

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.

Value

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

Author(s)

Svetlana K Eden, svetlanaeden@gmail.com

Examples

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 = "*")


[Package survSpearman version 1.0.1 Index]