I have 2 lists of ordered factors A and B, both contain thousands of items and have the same ordinal scale of about 30 levels. I want to find out how many items in A are equal to or within one level above or below the item at the same location in B
If this scale was numeric I would convert the ordered factors to numeric values and then do something like the following:
table(A==B || A==(B+1) || A==(B-1))
However, of course, '+' is not meaningful for factors. So what do I do? I could write a giant nested if statement or I could also change my ordinal scale to numbers according to their level only so that I can convert my ordered factors to numeric... but these seem like roundabout (and lengthy) solutions to something I'd assume is easy: How do I increase or decrease an ordered factor's level?
If I have
X<-ordered("b",levels=c("a","b","c"))
How do I make X[1]
equal "c"
by incrementing its current level?
Sidenote: Of course, in the first example above I'd need to account for factors that are on the lower and upper end of the scale, but I think (hope) this is something easy enough to figure out once my question has been answered.
Figured out a way of doing it. Someone actually posted a very useful answer that helped me figure this out, but has suddenly and unhelpfully/sadly taken it down. I actually wanted to give him/her the credit.
For the example in my OP, if you do the following you get an ordered factor where X[1] becomes "c"
You can then of course modify this code to alter by how many levels a particular element in an ordered factor is changed by and also modify this code to alter which element in an ordered factor is being changed.