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