string_misc: Miscellaneous string functions

string_dupR Documentation

Miscellaneous string functions

Description

Miscellaneous string functions that don't quite fit into the other categories.

Usage

string_dup(s, times)
string_insert(s, insert, position)
string_split(s, split, ...)
string_len(s)
string_reverse(s)
string_unique(s)
string_sort(s, descend = FALSE)

Arguments

s

A string (character) vector.

times

The number of times to duplicate a string.

insert

The string to insert.

position

The position index to which to insert the string.

split

The character by which to split a string vector.

...

Parameters passed to strsplit().

descend

Whether to sort in descending order (TRUE) or not (FALSE; the default).

Details

string_dup() acts the same as strrep(): it repeats a string n number of times.

string_insert() inserts a string at a specified position.

string_len() acts the same as nchar(): it counts the number of characters per vector element.

string_reverse() reverses the characters in a string.

string_split() acts the same as strsplit(): it splits a string by a specified character.

string_unique() obtains the distinct characters for each element in a vector.

string_sort() arranges the letters in the character vector in order if descend = FALSE (the default) and reverse order if descend = TRUE.

The synonym pattern of these functions are s_*() and *() (insert, len, and reverse). For the former pattern, you can replace with split, unique, and sort, as well.

See Also

https://github.com/robertschnitman/stringops

Examples

string_dup(rownames(mtcars), 3)
string_insert("abcd", "Z", 3)
string_len(rownames(mtcars))
string_reverse(rownames(mtcars))
string_split(rownames(mtcars), " ")
string_unique(rownames(mtcars))
string_sort(rownames(mtcars))
string_sort(rownames(mtcars), descend = TRUE)


robertschnitman/stringops documentation built on Aug. 15, 2022, 3:46 p.m.