refactorNum: Sort numeric factor levels by values

Description Usage Arguments Value Author(s) Examples

View source: R/factor.R

Description

Factor variables with numbers as levels are alphabetically ordered by default, which requires rearrangements for various purposes, e.g. modelling or visualizations. This function re-orders levels of numeric factor variables numerically.

Usage

1
refactorNum(x, decreasing = FALSE)

Arguments

x

A factor variable with numeric values as levels

decreasing

Logical, should the levels sorted descendingly?

Value

A factor variable, with sorted numeric values as levels

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

Examples

1
2
(nums <- factor(c("2","4","24","1","2","125","1","2","125")))
(nums.new <- refactorNum(nums))

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.