I simplified the dataset to demonstrate what I want to do. I'm not used to dealing with multiple columns. Here I made a simple data
data<-data.frame(id=c(1,1,1,2,2,2,2),
title_1=c(65,58,47,NA,25,27,43),
title_2=c(NA,NA,32,35,12,NA,1))
In my actual dataset there are so many columns, but for now I just named as above. My goal is to change the values of title_1 and title_2 by the following rule. If there is a number , change it to 1. If there is an NA value, change it to 0. But in my actual dataset, there are hundreds of columns named as title_1, title_2, ... , title_100, ... So, I cannot type all the column names. So for my simple data, I want to use the code that doesn't type the column names explicitly. My expected output is
data<-data.frame(id=c(1,1,1,2,2,2,2),
title_1=c(1,1,1,0,1,1,1),
title_2=c(0,0,1,1,1,0,1))