How can we create columns with highest values for each row ?
References:
https://rdrr.io/cran/dplyr/man/top_n.html
Selecting top N values within a group in a column using R
For e.g.
library(tidyverse)
iris %>% glimpse()
# my attempt
x = iris %>%
select(-Species) %>%
gather(measure,values) %>%
# hereafter got stuck
mutate(top_1 =
top_2 =
top3_3 = )
# expected_output contains same number of rows as input
expected_output = iris %>% mutate(top_1 = 1st highest value from the row (row wise),
top_2 = 2nd highest value from the row (row wise),
top_3 = 3rd highest value from the row (row wise))
# expected output first 3 rows looks like below:
iris[1:3,] %>%
mutate(top_1 = c(5.1,4.9,4.7), top_2 = c(3.5,3.0,3.2), top_3 = c(1.4,1.4,1.3))