79100747

Date: 2024-10-18 06:22:50
Score: 0.5
Natty:
Report link

Possible solution

This function seems to be working well. I have edited it to incorporate input.

multi.mixedorder <-\(data, cols, na.last = TRUE, decreasing = FALSE) {
  do.call(order, c(
    lapply(cols, function(col) {
      if (is.character(data[[col]])) {
        factor(data[[col]], levels = mixedsort(unique(data[[col]])))
      } else {
        data[[col]]
      }
    }),
    list(na.last = na.last, decreasing = decreasing)
  ))
}

DT[multi.mixedorder(DT, input),]
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Mohit