explode_dummies: Explode dummies columns into separate dummy variables

Description Usage Arguments Value Examples

View source: R/explode_dummies.r

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)

Example output

     rumination happiness activity
[1,]          0         0        1
[2,]          0         1        0
[3,]          1         1        0
[4,]          0         0        0
[5,]          1         0        1
     outlier_1 outlier_2 outlier_3 outlier_5
[1,]         1         0         0         0
[2,]         0         1         0         0
[3,]         0         0         1         0
[4,]         0         0         0         0
[5,]         0         0         0         1

autovarCore documentation built on May 29, 2017, 9:22 p.m.