I have a dataframe with three columns. I would like to populate the NAs that are in one column with values in another column, but I do not want to overwrite any data. How can I get the following results?
# Starting Dataframe:
DF$ST_1 <- c(100, NA, 100, 100, 200, 200, NA, NA, NA, NA, 200)
DF$ST_2 <- c(50, NA, 50, 50, 12, NA, NA, 50, 50, NA, 12)
DF$ST_3 <- c(5, NA, 5, 2, 3, 1, 1, 3, 4, 2, 11)
Results I want:
DF$ST <- c(100, NA, 100, 100, 200, 200, 1, 50, 50, 2, 200)
As you can see, I want to keep all the values in ST_1, and when there is an NA, fill it in with ST_2. Then, I want to keep all of the values from that merge, and fill in the remaining NAs with ST_3. There will still be some leftover NAs after all these merges.