Learn R Programming

ribiosUtils (version 1.7.7)

refactorNum: Sort numeric factor levels by values

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

refactorNum(x, decreasing = FALSE)

Value

A factor variable, with sorted numeric values as levels

Arguments

x

A factor variable with numeric values as levels

decreasing

Logical, should the levels sorted descendingly?

Author

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

Examples

Run this code

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

Run the code above in your browser using DataLab