У меня есть тиббл (взято из Как создать фиктивные переменные для группы другой переменной в tidyverse )
library(tidyverse)
input_data <- tribble( ~Subcat, ~Date, ~COMM1,~COMM2,~UOM,~AUC_TYPE,
#--|----------|-----|-----|----|----------------|
1, 2017-03-07, 40750,41400,"MT","English",
1, 2017-03-15, 40750,40000,"MT","English",
2, 2017-10-16, 41000,40500,"METER","Yankee",
2, 2017-11-06, 41010,40510,"METER","Yankee",
2, 2019-01-26, 50010,50510,"METER","English",
3, 2017-03-07, 40750,41400,"MT","English",
3, 2018-05-26, 50010,50510,"MT","English",
3, 2019-01-21, 40750,40200,"MT","English",
3, 2019-01-21, 40750,40200,"MT","English",
4, 2017-11-08, 37500,39000,"LTR","Dynamic Sealbid",
4, 2017-11-08, 37500,39000,"LTR","Dynamic Sealbid",
)
Желаемый вывод
output_data <- tribble( ~Subcat, ~Date, ~COMM1, ~COMM2, ~UOM_MT, ~UOM_METER ,~UOM_LTR, ~AUC_TYPE_English, ~`AUC_TYPE_Dynamic Sealbid`, ~AUC_TYPE_Yankee,
#--|----------|-----|-----|-|-|-|-|-|-|
1, 2017-03-07, 40750,41400,1,0,0,1,0,0,
1, 2017-03-15, 40750,40000,1,0,0,1,0,0,
2, 2017-10-16, 41000,40500,0,1,0,0,0,1,
2, 2017-11-06, 41010,40510,0,1,0,0,0,1,
2, 2019-01-26, 50010,50510,0,1,0,1,0,0,
3, 2017-03-07, 40750,41400,1,0,0,1,0,0,
3, 2018-05-26, 50010,50510,1,0,0,1,0,0,
3, 2019-01-21, 40750,40200,1,0,0,1,0,0,
3, 2019-01-21, 40750,40200,1,0,0,1,0,0,
4, 2017-11-08, 37500,39000,0,0,1,0,1,0,
4, 2017-11-08, 37500,39000,0,0,1,0,1,0,
)