[R] Invert Likert-Scale Values

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Aug 5 10:08:47 CEST 2007


(Ted Harding) wrote:
> On 04-Aug-07 22:02:33, William Revelle wrote:
>   
>> Alexis and John,
>>
>> To reverse a Likert like item, subtract the item from the maximum 
>> acceptable value + the minimum acceptable value,
>> That is, if
>> x <- 1:8
>> xreverse <- 9-x
>>
>> Bill
>>     
>
> A few of us have suggested this, but Alexis's welcome for the
> recode() suggestion indicates that by the time he gets round to
> this his Likert scale values have already become levels of a factor.
>
> Levels "1", "2", ... of a factor may look like integers, but they're
> not; and R will not let you do arithmetic on them:
>
>   
>> x<-factor(c(1,1,1,2,2,2))
>> x
>>     
> [1] 1 1 1 2 2 2
> Levels: 1 2
>   
>> y<-(3-x)
>>     
> Warning message: 
> "-" not meaningful for factors in: Ops.factor(3, x) 
>   
>> y
>>     
> [1] NA NA NA NA NA NA
>
> However, you can turn them back into integers, reverse, and then
> turn the results back into a factor:
>
>   
>> y <- factor(3 - as.integer(x))
>> y
>>     
> [1] 2 2 2 1 1 1
> Levels: 1 2
>
> So, even for factors, the insight undelying our suggestion of "-"
> is still valid! :)
>   
Er, wouldn't   y <- factor(x, levels=2:1, labels=1:2)  be more to the point?



More information about the R-help mailing list