Explode dummies columns into separate dummy variables

Share:

Description

This function takes a matrix with dummy outlier columns, where there are possibly multiple ones. We first merge these columns to one and then explode them to obtain one dummy variable per column.

Usage

1
explode_dummies(outlier_dummies)

Arguments

outlier_dummies

A matrix of outlier dummy variables in columns.

Value

A matrix with dummy variables in columns, each having one nonzero index. The columns are named outlier_x, with x being the 1-based row index of the position that this dummy variable is masking.

Examples

1
2
3
4
5
6
7
8
9
outlier_dummies <- matrix(NA,
                          nrow = 5,
                          ncol = 3,
                         dimnames = list(NULL, c('rumination', 'happiness', 'activity')))
outlier_dummies[, 1] <- c(0, 0, 1, 0, 1)
outlier_dummies[, 2] <- c(0, 1, 1, 0, 0)
outlier_dummies[, 3] <- c(1, 0, 0, 0, 1)
outlier_dummies
autovarCore:::explode_dummies(outlier_dummies)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.