onehot.Rd
One Hot Encoding of vector
onehot(x)
x | vector with D possible categorical values (will be coerced to factor) |
---|
matrix with D columns and same number of columns as length of x
onehot(1:5)#> as.factor(x)1 as.factor(x)2 as.factor(x)3 as.factor(x)4 as.factor(x)5 #> 1 1 0 0 0 0 #> 2 0 1 0 0 0 #> 3 0 0 1 0 0 #> 4 0 0 0 1 0 #> 5 0 0 0 0 1 #> attr(,"assign") #> [1] 1 1 1 1 1 #> attr(,"contrasts") #> attr(,"contrasts")$`as.factor(x)` #> [1] "contr.treatment" #>