I have a data frame that looks something likes this:
person <- c('x','y','z','a','b')
col <- c('AF, FMCC CUS, FMCC DEAL, HYUN', NA, 'CHR C, AFG, FMCC CUS', NA, 'AF')
Separation is by comma.So i wanted to split those where every category (AF, FMCC CUS,...etc) is a column that is a either a 1 or not. First step was the separation:
I used cSplit(df,'col',sep=',', stripWhite = TRUE)
ok! But FMCC CUS is present in the second column for person x but in the 3rd column col_3 for person a. How can I tell R that col_1 is exclusive for skill AF and col_2 is exclusive for skill FMCC CUS and so on till my last skill?
Also, when I get this, what is a good way to have each skill as a column and convert the data into a binary matrix where if the person has the skill it is a one. Otherwise, it is a zero.
I read about a function called model.matrix(). Any other suggestions would be great!