reassign: reassign Transforms a vector or matrix (mode character or...

View source: R/simmaphelper.R

reassignR Documentation

reassign Transforms a vector or matrix (mode character or numerical) into an integer object with the same dimension as the input object, with values on the range from 1:length(unique(x)). For an input vector x1, an integer vector x2 is returned with the following properties: (1) x2 equivalency relations of x2 are identical to those in x1 (2) sum(x2) <= sum(x1), for any x1 == abs(x1). (3) unique(x2x1>0) == 1:length(unique(x1x1>0)); if ignore0=FALSE, then unique(x2) == 1:length(unique(x1)) If x is a matrix then x is coerced to a vector and then coerced back to a matrix before returning.

Description

reassign

Transforms a vector or matrix (mode character or numerical) into an integer object with the same dimension as the input object, with values on the range from 1:length(unique(x)). For an input vector x1, an integer vector x2 is returned with the following properties: (1) x2 equivalency relations of x2 are identical to those in x1 (2) sum(x2) <= sum(x1), for any x1 == abs(x1). (3) unique(x2x1>0) == 1:length(unique(x1x1>0)); if ignore0=FALSE, then unique(x2) == 1:length(unique(x1))

If x is a matrix then x is coerced to a vector and then coerced back to a matrix before returning.

Usage

reassign(x, ignore0 = T)

Arguments

x

vector or matrix

ignore0

logical indicating if zeros should be ignored. Default true.

Value

integer vector if x is a vector; integer matrix if x is a matrix


JeffWeinell/misc.wrappers documentation built on Sept. 20, 2023, 12:42 p.m.