I'm using coalesce to combine two numerical columns into one.
I have a few set of columns, lets say one being A and B, that I need to combine; Currently, I'm using coalesce, but I need the 2nd column to be prioritized: ie. if both A and B have a value, I need the new variable to have the value from Column B, not Column A. Can I do this using coalesce, because I know it takes the first value, or do I need another function (or should I rearrange the column, which is less desirable?)
A B NewVarAB
1 1
3 5 5
This is my code:
rawdata2 <- (rawdata2 %>% mutate(Leaseconcat=coalesce(Leasemonthlytotal, Lease_Cost1))
%>% mutate(LicenseConcat=coalesce(LicenseMonthlyTotal, grosslicense1))
%>% mutate(NWAconcat=coalesce(NWAMonthlytotal, NWAGross1))
)