Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

char_map

Split a Character Vector into its Unique Elements and a Mapping on These


Description

This is implemented using a radix sort on the CHARSXPs directly, i.e. on the addresses of the strings in the global string cache. Hence, in contrast to unique, this function does not consider two strings equal which differ only in their encoding. Also, the order of the unique elements is undefined.

Usage

char_map(x)

map2char(map)

Arguments

x

a character vector. Long vectors are supported.

map

an object as returned by char_map.

Value

char_map returns an S3 object of class "char_map", which is a list with the following elements: (chars) the unique set of strings in x in undefined order, (idx) an integer (or - for long vectors - double) vector such that map$chars[map$idx] is identical to x (except maybe for attributes), (attributes) the attributes of x as a shallow copy of the corresponding pairlist.

map2char returns a character vector identical to x, including attributes.

Windows Support

Fully supported on Windows.

Lifecycle

options:
  alt='[Stable]'

Examples

x <- sample(letters, 100, replace = TRUE)
map <- char_map(x)
stopifnot(identical(x, map$chars[map$idx]))

names(x) <- 1:100
stopifnot(identical(x, map2char(char_map(x))))

bettermc

Enhanced Fork-Based Parallelization

v1.1.1
MIT + file LICENSE
Authors
Andreas Kersting [aut, cre, cph], GfK SE [cph], R Core team [ctb] ('etry()' and its print method borrow a lot from base R)
Initial release
2021-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.