Changing reference group in a numeric variable

Hello,

I have been able to change the reference group in my factor binary variables using the 'relevel' function.
I now need to do this for a numeric variable I have which I recoded to be 1 and 0 and the relevel function does not work for this type of variable.

At the moment, 0 is the reference group and I wish for 1 to become the reference.

Any help or guidance would be greatly appreciated!

Hi,

Is this what you like to do?

#Create a factor with levels 1, 0 (in that order)
x = factor(sample(0:1, 10, replace = T), levels = 1:0)
x
#>  [1] 0 0 0 1 1 0 0 1 1 0
#> Levels: 1 0

#Switch levels to 0, 1
x = factor(x, 0:1)
x
#>  [1] 0 0 0 1 1 0 0 1 1 0
#> Levels: 0 1

Created on 2021-08-02 by the reprex package (v2.0.0)

Hope this helps,
PJ

Hi,

Thank you so much for your response. It worked!

Best wishes,
Poppy

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.