Description Usage Arguments Value Examples
View source: R/misc_functions.R
Given a data frame of factor variables, this function returns a numeric matrix of 0–1 dummy-coded variables.
1 | dummyCodeFactorDf(dat)
|
dat |
A data frame of factor variables |
A numeric matrix of 0–1 dummy coded variables
1 2 | dd <- data.frame(a=factor(1:8), b=factor(letters[1:8]), stringsAsFactors = TRUE)
dummyCodeFactorDf(dd)
|
a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 b_a b_b b_c b_d b_e b_f b_g b_h
[1,] 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
[2,] 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0
[3,] 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0
[4,] 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0
[5,] 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0
[6,] 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0
[7,] 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0
[8,] 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.