Hi to all useRs on the list.

I want to know if there is a function in R which evaluates if observations of 
two factors (similar but with unequal levels) in a data frame are equal at row 
level.

Example of dataset:

var1 <- c(1, 2, 3, 2, 1)
var2 <- c(1, 3, 3, 4, 2)
dat <- data.frame(var1, var2)
dat$var1 <- factor(dat$var1, labels = c("low", "medium", "high"))
dat$var2 <- factor(dat$var2, labels = c("low", "medium", "high", "very high"))

What I want as a result is a logical vector that says if observation [i, 1] is 
equal to observation [i, 2].

Something like...

var1[1] == var2[1]  # TRUE
var1[2] == var2[2]  # FALSE
var1[3] == var2[3]  # TRUE
var1[4] == var2[4]  # FALSE
var1[4] == var2[4]  # FALSE

I've tried equal signs (==), commands such as "identical" and "all.equal" in 
"for loops" and I can't make it work for factors. 

It seems very simple but I just don't find the way to do it.

Regards,

Mart�n 

                                          
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to