I am trying to merge 2 columns within the same dataset in order to condense the number of columns.
The dataset currently looks like this:
Year Var1 Var2
2014 NA 123
2014 NA 155
2015 541 NA
2015 432 NA
2016 NA 124
etc
I wish the dataset to look like
Year Var1/2
2014 123
2014 155
2015 541
2015 432
2016 124
Any Help is grealty apprecitated.
You should be able to just use
with(mydf, pmax(Var1, Var2, na.rm = TRUE))
.Here's a sample
data.frame
. Note row 5.Assign it to a column and you're good to go.