Find the max/min value in a pair of columns
dplyr, r, tidyverse
Solution
You could try `pmax`
mutate(df, C=pmax(A,B))
# A B C
#1 0.2 0.1 0.2
#2 0.2 0.3 0.3
#3 0.5 0.1 0.5
#4 0.7 0.9 0.9
#5 0.8 0.9 0.9
#6 0.4 0.2 0.4
`max` gets you the `maximum` single value of the two columns instead of the "row" maximum
Problem
My data looks like this: ``` df <- tribble( ~A, ~B, 0.2, 0.1, 0.2, 0.3, 0.5, 0.1, 0.7, 0.9, 0.8, 0.9, 0.4, 0.2) ``` How might I select the max/min value between `A` and `B`? Desired Output: ``` A B C 1 0.2 0.1 0.2 2 0.2 0.3 0.3 3 0.5 0.1 0.5 4 0.7 0.9 0.9 5 0.8 0.9 0.9 6 0.4 0.2 0.4 ```