vector_to_dummy: Create a dummy matrix from the elements in a vector

Description Usage Arguments Value Author(s) See Also Examples

View source: R/vector_to_dummy.r

Description

Create a dummy matrix based on the elements of a vector. Each column in the produced matrix is a dummy indicator.

Usage

1
  vector_to_dummy(avector)

Arguments

avector

a numeric vector

Value

A matrix of dummy variables

Author(s)

Gaston Sanchez

See Also

list_to_dummy, factor_to_dummy

Examples

1
2
3
4
5
# let's say you have a list like this
num_vec = c(2, 3, 1, 4)

# get dummy matrix
vector_to_dummy(num_vec)

Example output

Attaching package: 'turner'

The following object is masked from 'package:base':

    lengths

      [,1] [,2] [,3] [,4]
 [1,]    1    0    0    0
 [2,]    1    0    0    0
 [3,]    0    1    0    0
 [4,]    0    1    0    0
 [5,]    0    1    0    0
 [6,]    0    0    1    0
 [7,]    0    0    0    1
 [8,]    0    0    0    1
 [9,]    0    0    0    1
[10,]    0    0    0    1

turner documentation built on May 2, 2019, 8:35 a.m.