I am hoping to find a vectorized approach to get the absolute maximum value from multiple columns in a data frame.
Basically is there an equivalent to the pmax function for getting absolute maximums.
test_df <- tibble(
some_identifier = c("apple", "tunafish", "turkey_sandwich"),
val_a = c(-1, 2, 0),
val_b = c(-3, 3, NA),
val_c = c(2, 3, 1)
)
# this is what abs_max column should be
test_df$abs_max <- c(-3, 3, 1)
test_df
# A tibble: 3 x 5
some_identifier val_a val_b val_c abs_max
<chr> <dbl> <dbl> <dbl> <dbl>
1 apple -1 -3 2 -3
2 tunafish 2 3 3 3
3 turkey_sandwich 0 NA 1 1
The abs_max column is what I want to create. A less than optimal solution may be to loop through each row; but wanted to reach out to identify possible a better method.