简体   繁体   English

更改日期顺序

[英]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我尝试使用 ordered 语句,但显示错误,请帮助

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这就是它的显示方式 -在此处输入图片描述

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM