This is the original dataframe just like this. I want to know the max value between 'a' and 'b' ,and mutate max value and variavble name as two columns.
df <- data.frame(lon = c(102,103,104,105),
lat = c(31,32,33,34),
a = c(4,3,7,6),
b = c(5,2,4,9))
The target dataframe is like this.
dftarget <- data.frame(lon = c(102,103,104,105),
lat = c(31,32,33,34),
a = c(4,3,7,6),
b = c(5,2,4,9),
max = c(5,3,7,9),
type = c('b','a','a','b'))