Skip to content
Prev 333659 / 398506 Next

convert data frame: two variables into _one_ binary variable

In R,  as.logical() and other functions treat anything >0 as TRUE.  Thus:

Rgames> foo<-sample(0:5,10,rep=TRUE)
Rgames> foo
 [1] 0 5 1 0 1 5 2 5 4 5
Rgames> as.logical(foo)
 [1] FALSE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE

For your case,  simply  (womensrole$agree>womensrole$disagree) will return
the logical vector you want.
Just for info,
In R,  as.logical() and other functions treat anything >0 as TRUE.  Thus:

Rgames> foo<-sample(0:5,10,rep=TRUE)
Rgames> foo
 [1] 0 5 1 0 1 5 2 5 4 5
Rgames> as.logical(foo)
 [1] FALSE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE



Liviu Andronic wrote

            
--
View this message in context: http://r.789695.n4.nabble.com/convert-data-frame-two-variables-into-one-binary-variable-tp4681098p4681123.html
Sent from the R help mailing list archive at Nabble.com.