Monday, 9 September 2013

Logical vector with multiple columns in R

Logical vector with multiple columns in R

I have te following dataframe:
a b c d e
TRUE TRUE FALSE TRUE TRUE
FALSE TRUE TRUE TRUE FALSE
TRUE TRUE FALSE TRUE TRUE
TRUE TRUE TRUE FALSE TRUE
TRUE TRUE TRUE TRUE TRUE
TRUE TRUE TRUE TRUE TRUE
I would like to create an extra column , say f, with the following logic:
TRUE = If all the columns in the corresponding row are all TRUE or all FALSE.
FALSE = if one or more colums differ from the other columns in the
corresponding row.
In this example the output would be
a b c d e f
TRUE TRUE FALSE TRUE TRUE FALSE
FALSE TRUE TRUE TRUE FALSE FALSE
TRUE TRUE FALSE TRUE TRUE FALSE
TRUE TRUE TRUE FALSE TRUE FALSE
TRUE TRUE TRUE TRUE TRUE TRUE
TRUE TRUE TRUE TRUE TRUE TRUE

No comments:

Post a Comment