Learn R Programming

ribiosUtils (version 1.7.7)

shortenStr: Shorten strings to a given number of characters

Description

Shorten strings to a given number of characters

Usage

shortenStr(str, nchar = 8)

Value

A vector of strings of the same length as the input, with each string shortened to the desired length

Strings with more characters than nchar will be shortened.

Arguments

str

A vector of strings

nchar

The maximal number of characters to keep

Examples

Run this code

inputStrs <- c("abc", "abcd", "abcde", NA)
shortenStr(inputStrs, nchar=4)
## expected outcome: abc, abcd, abcd..., NA

Run the code above in your browser using DataLab