提问人:RAGHAV ALAWADHI 提问时间:1/23/2023 最后编辑:zx8754RAGHAV ALAWADHI 更新时间:1/23/2023 访问量:35
更改天数顺序
Changing the order of days
问:
我无法按时间顺序显示一周中的几天,并且在可视化数据时,它看起来不正确。
我尝试使用命令语句,但它显示一个错误,请帮忙
这是我的代码——
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)
这就是它的显示方式 - 在此处输入图像描述
答:
0赞
dario
1/23/2023
#1
expl <- data.frame(days = c("tue", "mon", "wed"))
library(dplyr)
expl %>%
mutate(days = factor(days, levels = c("mon", "tue", "wed"))) %>%
arrange(days)
返回:
days
1 mon
2 tue
3 wed
评论
factor(day_of_week, levels= c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"))