I have the dataframe below and I would like to sort it by the datetime column Run Date (from earliest to latest dates) but for each specific factor of the column SN which in this case has 2 levels 134080504 and T133230503A.
dat<-structure(list(SN = c("134080504", "134080504", "134080504",
"134080504", "134080504", "134080504", "134080504", "134080504",
"134080504", "134080504", "134080504", "134080504", "134080504",
"134080504", "134080504", "134080504", "134080504", "134080504",
"134080504", "134080504", "134080504", "134080504", "134080504",
"134080504", "134080504", "134080504", "134080504", "T133230503A",
"T133230503A", "T133230503A", "T133230503A", "T133230503A", "T133230503A",
"T133230503A", "T133230503A", "T133230503A", "T133230503A", "T133230503A",
"T133230503A", "T133230503A", "T133230503A", "T133230503A", "T133230503A",
"T133230503A", "T133230503A", "T133230503A", "T133230503A", "T133230503A",
"T133230503A", "T133230503A"), `Status [F/S]` = c("S", "S", "S",
"S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
"S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
"S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
"S", "S", "S", "S", "S", "S", "S", "S"), `Run Date` = structure(c(1256466600,
1256264100, 1256228100, 1256219100, 1256202000, 1228897800, 1218629760,
1177851660, 1177462800, 1172398500, 1171795800, 1164396600, 1163971800,
1157567400, 1157224500, 1157079000, 1156874100, 1156752000, 1156410000,
1148266800, 1147984200, 1147780800, 1147177800, 1142753400, 1141551000,
1141372800, 1130468400, 1625724600, 1625724600, 1625724600, 1623628800,
1623628800, 1623628800, 1623358800, 1623358800, 1623358800, 1566812460,
1566812460, 1566812460, 1566665700, 1566665700, 1566665700, 1554503520,
1554503520, 1554503520, 1554161880, 1554161880, 1554161880, 1553929200,
1553929200), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA,
50L), class = c("tbl_df", "tbl", "data.frame"))
>Solution :
Try it!
library(tidyverse)
dat %>% arrange(`Run Date`, SN)