I have a dataframe with around 300 features and 1million observations. I have created a list variable with has the index values that contain 80% of data as NA values.
My index list has -> 2,4 I want to create an indicator variable for the columns with index 2 ,3 of dataframe to replace NA values with "0" and other values in the column with "1"
I tried to loop through each row but as data is huge its taking long time to loop it.
Input dataframe -> df
row col1 col2 col3
a NA 1 3
a NA 1 NA
a 2 2 NA
Expected output:
row col1 col2 col3
a 0 1 1
a 0 1 0
a 1 2 0
Can anyone point me to the right direction to achieve this faster.
Thanks,
Renuka