I currently access the "v" column of the "two" data frame dynamically and I'd like to turn it into a factor with levels from the "one" data frame. I am currently getting NAs when I use factor() on two[,variable] . Any idea how to get this to work?
one =data.frame(v=c("B","A"))
two = data.frame(v=c("A","B"))
variable = "v"
two[,variable] = factor(two[,variable] ,levels = one$v, ordered = TRUE)
v
1 <NA>
2 <NA>