i want to replace all values greater than 0 to 0 and all the values equal to 0 to 1. i am able to convert one by one but what is the best and easiest way in single line of code ..?
i have tried the below approach but its changing everything to 0 or everything to 1
df <- data.frame(cc=c(1,NA,3,NA,4,NA,23,17,NA,0),
bb=c(0,NA,12,NA,2,0,NA,12,14,0),
dd=c(12,0,0,NA,3,0,NA,23,7,9))
df1 <- df %>% mutate(across(c(cc, bb,dd), ~replace(., .>0, 0)),across(c(cc, bb,dd), ~replace(., .=0, 1)))
the overall objective is to replace values greater than 0 to 0 and values equals to 0 to 1