Hi there,
I'm trying to figure out how to group by operators all shipments id's assigned to them. spread()
& transpose()
were what I thought of or a for loop.
transpose()
generated a list, which I knew wasn't what I would expect but expresses what I'm trying to achieve.
library(tidyverse)
# Sample data
dt <- tibble(
"Shipment ID" = c("S00001009", "S00001033",
"S00001034","S00001036", "S00001038", "S00001039", "S00001040","S00001041"),
"Job Operator" = c("Wayne Martin", "Wayne Martin", "Emil Manuel",
"Emil Manuel", "Emil Manuel", "Joanne Lano","Joanne Lano" ,"Tony Solis")
)
# Group by operators all Shipment ID's assigned to them.
dt %>% group_by(`Job Operator`) %>%
transpose()
# Expected output:
tibble(
"Job Operator" = c("Wayne Martin","Emil Manuel",
"Joanne Lano","Tony Solis"),
"Shipment ID" = c("S00001009, S00001033","S00001034, S00001036,
S00001038","S00001039, S00001040", "S00001041")
)
`Job Operator` `Shipment ID`
<chr> <chr>
1 Wayne Martin S00001009, S00001033
2 Emil Manuel S00001034, S00001036, S00001038
3 Joanne Lano S00001039, S00001040
4 Tony Solis S00001041
Any insight would be much appreciated.
Best regards,
LF.