splitMatrix: Split matrix

Description Usage Arguments Details Value Examples

View source: R/splitMatrix.R

Description

Given a numeric matrix, this function performs a column-wise separation of positive values from negative values, producing a return matrix with twice the number of columns as the input matrix.

Usage

1

Arguments

x

A numeric matrix

Details

Conceptually, this function makes two copies of the input matrix (we will call them A and B). It replaces all negative values in copy A with 0, and all positive values in copy B with 0. It then multiplies copy B by -1, and finally combines (via cbind) the two copies together column-wise. The strings "_pos" and "_neg" are appended to the original column names to generate the column names for the new matrix.

Value

A matrix devoid of negative values with twice the number of columns as the input matrix.

Examples

1
2
x = matrix(rnorm(9), 3, 3)
splitMatrix(x)

MPCary/DEXICA documentation built on June 26, 2017, 7:35 p.m.