mapchr: Manipulate individual elements in a character vector

Description Usage Arguments Details Value See Also Examples

View source: R/mapchr.R

Description

Apply functions that manipulate character/string vectors. Useful for reordering the characters in each vector element, for example.

Usage

1
2
3
4
mapchr(f, x)
jumble(x)
is.upper(x)
is.lower(x)

Arguments

f

Function to apply to the character vector 'x'.

x

Character vector.

Details

'mapchr()' is a general functional for altering character vectors: apply any function to each of its elements. 'jumble(x)' randomly changes the order of the characters in every element. Similar to 'map_chr()' from the 'purrr' library with the exception that the former only accepts character vectors as the data input. These functions are useful when manipulating the arrangement of the characters is desired. Finally, 'is.upper()' and 'is.lower()' test whether each element in a string vector is all uppercase or lowercase.

Value

Vector.

See Also

https://github.com/robertschnitman/afp, lapply

Examples

1
2
3
4
5
6
7
8
9
# 1. Manipulating the letter ordering in each vector elemetn.
rn_mc <- rownames(mtcars)
mapchr(function(x) paste0(x, collapse = '|'), rn_mc)
jumble(rn_mc)

# 2. Testing for uppercase or lowercase.
chr <- c('TEST', 'test', 'tEsT')
is.upper(chr) # TRUE FALSE FALSE
is.lower(chr) # FALSE  TRUE FALSE

robertschnitman/afp documentation built on Aug. 9, 2020, 9:46 a.m.