I have two factor variables in a data frame and the end goal is to combine both columns to find a list of the unique factors of both the columns combined (some of the factors in variable one are repeated in variable two). To do this I need a vector of length 2n to perform the 'unique' function on (stacked vector in code below). However I am having problems combining these two vectors using the 'stack' function.
x<-rep(c("a","b", "c"), each=3)
x<-as.vector(x)
y<-rep(c("a","b", "z"), each=3)
y<-as.vector(y)
combined<-data.frame(x,y)
stacked<-stack(combined)
unique(stacked)
I don't understand the error message I am getting on the 2nd last line. I know this must be something so simple but I just can't see it! If anyone knows or has a more elegant way of solving this problem please reply!