Here is my dataframe:
col_1 <- c(1,2,NA,4,5)
temp_col_1 <-c(12,2,2,3,4)
col_2 <- c(1,23,423,NA,23)
temp_col_2 <-c(1,2,23,4,5)
df_test<-data.frame(col_1,temp_col_1,col_2, temp_col_2)
In column col_1 I would like to replace NA with corresponding value from temp_col_1 and do the same for col_2 and temp_col_2
I know how to do it manually with ifelse statement, the problem is that I have tones of columns with pattern col_name and temp_col_name and I wonder how I can automate it.
I tried different things like df_test[,paste('temp_','col_1]', but nothing worked. Any suggestions?
Aucun commentaire:
Enregistrer un commentaire