I merged various dataframes in R, which had variables with the same name. In the merged file I got variables names as varA, varA.x, varA.x1, varA.x.y, etc. I want to create a file merging the content of all these variables in a single column. As an example of my file:
ID weight age varA varA.x varA.x.y varA.x.y.1
1 50 30 2 NA NA NA
2 78 34 NA 3 NA NA
3 56 56 NA NA NA 6
4 56 67 NA NA 7 NA
I want a file that looks like:
ID weight age varA
1 50 30 2
2 78 34 3
3 56 56 6
4 56 67 7
It is not feasible to use ifelse: `data$varA = ifelse(is.na(varA.x),varA.y,varA.x), because the statement would be too long as I have so many repeated variables.
Can you help me, please? Thank you so much.