SplitToDummy.Rd
Split the strings of a character vector, put together all the unique pieces and return a matrix of dummy vectors for each single value.
SplitToDummy(x, split = ",", ...)
character vector, each element of which is to be split. Other inputs, including a factor, will give an error.
character vector (or object which can be coerced to such) containing regular expression(s) (unless fixed = TRUE
) to use for splitting. If empty matches occur, in particular if split
has length 0, x
is split into single characters. If split
has length greater than 1, it is re-cycled along x.
the dots are passed on to strsplit
a data.frame containing x
and all the found dummy vectors
d.frm <- data.frame(id=1:5, txt=c("A,C,D", "A","B,C","D","D,E"))
SplitToDummy(d.frm$txt)
#> x A B C D E
#> 1 A,C,D 1 0 1 1 0
#> 2 A 1 0 0 0 0
#> 3 B,C 0 1 1 0 0
#> 4 D 0 0 0 1 0
#> 5 D,E 0 0 0 1 1