Home > Back-end >  Changing the order of days
Changing the order of days

Time:01-23

I am unable to present my days of the week in a chronological order, and while visualizing the data, it doesn't looks right.

I tried using ordered statement, but it shows me an error, please help

This is my code -

avg_ride_day <- cyclistic_data %>%
  filter(bike_type != "docked_bike") %>%
  group_by(user_type, day_of_week) %>%
  summarise(avg_time_min = mean(ride_length)/60, median_time = median(ride_length)/60, 
            max_time = max(ride_length)/60, min_time = min(ride_length)/60) %>%
  arrange(day_of_week)

And this is how it is displayed - enter image description here

CodePudding user response:

expl <- data.frame(days = c("tue", "mon", "wed"))

library(dplyr)

expl %>% 
  mutate(days = factor(days, levels = c("mon", "tue", "wed"))) %>% 
  arrange(days)

returns:

  days
1  mon
2  tue
3  wed
  • Related