- This message: [ Message body ] [ More options ]
- Related messages: [ Next message ] [ Previous message ] [ Next in thread ] [ Replies ]

From: Chris Bergstresser <chris_at_subtlety.com>

Date: Wed 02 Mar 2005 - 09:45:36 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 02 09:56:11 2005

Date: Wed 02 Mar 2005 - 09:45:36 EST

Hi all --

I've got two columns, both of which correspond to three factor levels (e.g., column1 is "a", "b", or "c"; column2 is "x", "y", or "z"). I'd like to generate a third column, consisting on whether the two factors are correctly aligned for a given case (in this example, "a" corresponds to "x", "b" to "y", and "c" to "z"). For example:

a x TRUE

a y FALSE

b y TRUE

c z TRUE

b x FALSE

Several questions:

The easiest way seemed to me to be comparing the numeric values across columns, but the encodings are (a=1, b=2, c=3) and (x=1, y=3, z=2). Is there a way to change the underlying value representing each factor, so I could just run an equality on them?

Is there a simple way to check for correspondence without recoding the factors?

> f = gl(3, 1, 6, labels=c("a", "b", "c"))

* > f
*

[1] a b c a b c

Levels: a b c

> as.numeric(levels(f))[f]

[1] NA NA NA NA NA NA

Warning message:

NAs introduced by coercion

> as.numeric(as.character(f))

[1] NA NA NA NA NA NA

Warning message:

NAs introduced by coercion

> as.numeric(f)

[1] 1 2 3 1 2 3

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 02 09:56:11 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:30:39 EST
*