refactor: Convert a vector of 0-based indexed integers into a factor

View source: R/defactor_refactor.R

refactorR Documentation

Convert a vector of 0-based indexed integers into a factor

Description

Convert a 0-based indexed vector, which is the output of xgboost for classification, into an R factor.

Usage

refactor(x, levels)

Arguments

x

vector of integers representing a factor, with 0-based indexing.

levels

levels of the factor to recreate, given in order.

Value

A vector of class factor

Examples

xf <- factor(c("a", "b", "a"))
xi <- defactor(xf)
xi
xf2 <- refactor(xi, levels=c("a", "b"))
identical(xf, xf2)

jiho/joml documentation built on Dec. 6, 2023, 5:50 a.m.