replace_ordinal: Replace missing categories on ordinal scale

Description Usage Arguments Details Value Examples

View source: R/replace.r

Description

Rescale an ordinal scale to replace missing categories. This will assure that the currently present ordinal categories are sequential.

Usage

1

Arguments

x

an object with ordinal categories

replace

optional a positive integer or a vector of replacement values. See Details.

Details

By default replace_ordinal function replaces the sorted unique elements in x with a numeric series 1:n where n is the number of categories in the data. The type of the object is preserved, e.g., if the object type of x is integer vector, matrix or a data.frame containing integers, the replacement series as well as the returning object will be integer as well.

If replace has length 1 and is numeric (in the sense of is.numeric), the replacement series will start with replace. Typical usage might be replace = 0 for a series starting with 0.

Alternatively, user can provide vector of replacement values. This vector will be used in provided order and the returned object will have an elements of the requested type. The vector must be at least as long as the number of categories in x, but can be larger. This permits replacement with arbitrary categories, such as with the build-in letters.

Value

x where categories are replaced with an numeric series of with the provided replacement values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
foo = c(1, 3, 5)
bar = c(1, 2, 3)
identical(replace_ordinal(foo), bar)

foo = c(1, 3, 5)
bar = c(5, 6, 7)
identical(replace_ordinal(foo, 5), bar)

foo = c(1, 5, 3)
bar = c("a", "c", "b")
identical(replace_ordinal(foo, letters), bar)

bioDS/phyloRNA documentation built on Feb. 21, 2022, 3:28 p.m.