How can I recode 0 to 1 and 1 to 0 for columns i1:i3 in the below sample dataset?
df <- data.frame(id = c(11,22,33),
i1 = c(0,1,NA),
i2 = c(1,1,0),
i3 = c(0,NA,1))
> df
id i1 i2 i3
1 11 0 1 0
2 22 1 1 NA
3 33 NA 0 1
I have tens of columns starting with i... So I need a indexing condition to apply only for those columns. The desired output would be:
> df1
id i1 i2 i3
1 11 1 0 1
2 22 0 0 NA
3 33 NA 1 0