How to arrange data chronologically by month

Given below is the data I have. Month & the calories burnt in the corresponding month. I want to arrange the data by month but unable to do so.

Month

Total_Cal

April 1242.00
August 7337.00
December 11356.00
July 1596.00
June 1693.00
March 511.62
May 1469.00
November 10797.00
October 9690.00
September 7304.00

The months will sort by alphabetical order if they are character, so you need to convert them to factor. You can use the built-in array of month names (month.name).

library(dplyr)

your_data_frame %>%
  mutate(
    Month = factor(Month, levels = month.name)
  ) %>%
  arrange(Month)
1 Like

This works. Thanks a lot!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.