Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing the order of days

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 –

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading