I have a tibble, d, arranged such that value is decreasing.
I want to gather all the same types together, whilst maintaining the relative arrangements of the first entry of each type. This is shown in d_sorted.
A normal group_by() won't work for me.
How can I sort my data?
library(tidyverse)
#before
d <- tribble(
~"type", ~"value",
"R" , 109,
"C" , 105,
"B" , 80,
"W" , 77,
"R" , 70,
"W" , 66,
"A" , 58,
"C" , 55
)
#after
d_sorted <- tribble(
~"type", ~"value",
"R" , 109,
"R" , 70,
"C" , 105,
"C" , 55,
"B" , 80,
"W" , 77,
"W" , 66,
"A" , 58
)
Created on 2021-04-15 by the reprex package (v1.0.0)