I have a dataframe
descriptions names cutoffs vals
1 a A 90 1
2 a A 91 2
3 a B 90 3
4 a C 90 4
that I want to pivot_wider(names_from = names, values_from = vals)
into the form
description A B C
1 a 1 3 4
If there are 2+ rows with the same name, I want to fill in values_from
with the row with the higher cutoff
column value.
I know that if I wanted the max value out of the vals
column, I could do values_fn = max
, so
I tried adding values_fn = max(cutoffs)
as an additional parameter to pivot_wider()
but it did not work.
How can I get to my desired end result?