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

new_factor

Factor/ordered factor S3 class


Description

A factor is an integer with attribute levels, a character vector. There should be one level for each integer between 1 and max(x). An ordered factor has the same properties as a factor, but possesses an extra class that marks levels as having a total ordering.

Usage

new_factor(x = integer(), levels = character(), ..., class = character())

new_ordered(x = integer(), levels = character())

## S3 method for class 'factor'
vec_ptype2(x, y, ...)

## S3 method for class 'ordered'
vec_ptype2(x, y, ...)

## S3 method for class 'factor'
vec_cast(x, to, ...)

## S3 method for class 'ordered'
vec_cast(x, to, ...)

Arguments

x

Integer values which index in to levels.

levels

Character vector of labels.

..., class

Used to for subclasses.

Details

These functions help the base factor and ordered factor classes fit in to the vctrs type system by providing constructors, coercion functions, and casting functions. new_factor() and new_ordered() are low-level constructors - they only check that types, but not values, are valid, so are for expert use only.


vctrs

Vector Helpers

v0.3.8
MIT + file LICENSE
Authors
Hadley Wickham [aut], Lionel Henry [aut, cre], Davis Vaughan [aut], data.table team [cph] (Radix sort based on data.table's forder() and their contribution to R's order()), RStudio [cph]
Initial release

We don't support your browser anymore

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