factor2char: Convert Index and String Vector into CharacterVector, and...

View source: R/RcppExports.R

factor2charR Documentation

Convert Index and String Vector into CharacterVector, and vice versa

Description

These two functions are an illustration of how as.character and as.factor may be reimplemented at the C++ level.

Usage

factor2char(iv)

char2factor(sv)

Arguments

iv

A Integer Vector corresponding to numeric representation of the factor This vector is also expected to have an attribute ‘levels’ with the factor levels

sv

A String Vector

Value

A Character Vector which at each position contains the level value of the corresponding index, or a Factor, depending on the function

Examples

f <- as.factor(c("red", "green", "blue", "red"))
factor2char(f);
f <- as.factor(c("red", "green", "blue", "red"))
v <- factor2char(f);
char2factor(v)

eddelbuettel/rcppexamples documentation built on March 8, 2024, 1:37 p.m.