fctr {data.table} | R Documentation |
Create a factor retaining original ordering
Description
Creates a factor
.
By default, the output will have its levels in the original order, i.e., levels = unique(x)
, as opposed to factor
's default where levels = sort(unique(x))
.
Usage
fctr(x, levels=unique(x), ..., sort=FALSE, rev=FALSE)
Arguments
x |
Object to be turned into a factor. |
levels |
Levels for the new factor; |
... |
Other arguments passed to |
sort |
Logical, default |
rev |
Logical, default |
Value
Factor vector having levels ordered according to the order of elements in input and arguments sort
, rev
.
Examples
levels(factor(c("b","a","c")))
levels(fctr(c("b","a","c")))
levels(fctr(c("b","a","c"), rev=TRUE))
levels(fctr(c("b","a","c"), sort=TRUE))
levels(fctr(c("b","a","c"), sort=TRUE, rev=TRUE))
[Package data.table version 1.17.99 Index]