# NOT RUN {
x <- factor(c('abc','de','f','de'))
xd <- factorToDummies(x,'x')
xd
# x.abc x.de
# [1,] 1 0
# [2,] 0 1
# [3,] 0 0
# [4,] 0 1
# attr(,"factorInfo")
# attr(,"factorInfo")$fname
# [1] "x"
#
# attr(,"factorInfo")$omitLast
# [1] TRUE
#
# attr(,"factorInfo")$fullLvls
# [1] "abc" "de" "f"
w <- factor(c('de','abc','abc'))
wd <- factorToDummies(w,'x',factorInfo=attr(xd,'factorInfo'))
wd
# x.abc x.de
# [1,] 0 1
# [2,] 1 0
# [3,] 1 0
# attr(,"factorInfo")
# attr(,"factorInfo")$fname
# [1] "x"
#
# attr(,"factorInfo")$omitLast
# [1] TRUE
#
# attr(,"factorInfo")$fullLvls
# [1] "abc" "de" "f"
# }
Run the code above in your browser using DataLab