I have a dataframe like this
Day <- c("Day1","Day20","Day5","Day10")
A <- c (5,7,2,0)
B <- c(15,12,16,30)
df <- data.frame(Day,A,B)
df$Day <- as.character(df$Day)
The first column is a character and hence I used this solution to sort this dataframe but not quite getting it right since this only sorts the first column and leaves the column 2 & 3 unchanged.
df$Day <- df$Day[order(nchar(df$Day), df$Day)]
My desired output is
Day A B
Day1 5 15
Day5 2 16
Day10 0 30
Day20 7 12
What am I missing here? Kindly provide some inputs.