I have 2 columns of data with the same type of data (Strings).
I want to join the levels of the columns. ie. we have:
col1 col2
Bob John
Tom Bob
Frank Jane
Jim Bob
Tom Bob
... ... (and so on)
now col1 has 4 levels (Bob, Tom Frank, Jim) and col2 has 3 levels (John, Jane, Bob)
But I want both columns to have all the factor levels (Bob, Tom, Frank, Jim, Jane, John), as to later replace each of the 'names' with a unique id, such that the final output would be:
col1 col2
1 5
2 1
3 6
4 1
2 1
that is Bob -> 1, Tom -> 2, etc. in both columns.
Any ideas :) ?
edit: Thanks all for the wonderful answers! You are all awesome as far as I know :)
See Question&Answers more detail:os