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
You want the factors to include all the unique names from both columns.
col1 <- factor(c("Bob", "Tom", "Frank", "Jim", "Tom"))
col2 <- factor(c("John", "Bob", "Jane", "Bob", "Bob"))
mynames <- unique(c(levels(col1), levels(col2)))
fcol1 <- factor(col1, levels = mynames)
fcol2 <- factor(col2, levels = mynames)
EDIT: a little nicer if you replace the third line with this:
mynames <- union(levels(col1), levels(col2))