I am trying to convert list of factors to matrix for example:
myLists:
[[1]]
[1] "RA" "FZFG" "BR"
[[2]]
[1] "RA"
[[3]]
[1] ""
[[4]]
[1] ""
to
RA FZFG BR
1 1 1
1 0 0
0 0 0
0 0 0
I tried to do the following:
allFactors<-c("RA","FZFG","BR")
mat<-model.matrix(~allFactors, data =myLists)
but have ths error:
Error in data.frame(c("RA", "FZFG", "BR"), "RA", "", "", "", "", c("RA", : arguments imply differing number of rows: 3, 1, 2, 4, 5, 7, 6, 8, 9
Any help on this is appreciated.
One option is
Or using
base R