0

I have the following dataframe and Im trying to sort by the Week column but I get the same result.

Actualdf2<-structure(list(Week = structure(1:20, .Label = c("1", "10", "11", 
"12", "13", "14", "15", "16", "17", "18", "19", "2", "20", "3", 
"4", "5", "6", "7", "8", "9"), class = "factor"), `Actual target` = c(7L, 
8L, 4L, 2L, 12L, 37L, 29L, 33L, 31L, 47L, 10L, 12L, 52L, 19L, 
19L, 27L, 29L, 18L, 25L, 8L)), row.names = c(NA, 20L), class = "data.frame")

Actualdf2<-Actualdf2[
    with(Actualdf2, order(as.numeric(Week))),
]
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • 2
    Your issue is R-FAQ 7.10 [How to convert factors to numerics](https://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f), which confusingly needs to happen via `character` class. Use `as.numeric(as.character(Week))` – Gregor Thomas Sep 16 '21 at 12:58
  • correct it did this – firmo23 Sep 16 '21 at 13:00

0 Answers0