1)从flights 数据表中挑选出以下变量: (vear,month,day, hour, origin, dep delay, distance. carrier),将生产的新表保存为 flight1。 (2)从 weather 数据表中挑选出以下变量: (year, month, day, hour, origin, humid, wind speed),将生产的新表保存为 weather1。 (3)将 flight1 表和 weather1 表根据共同变量进行内连接,随机抽取 100000 行数据,将生产的结果保存为 flight weather。(提示: sample n0函数,不用重复抽取)(4)从 flight weather 表中对三个出发机场按照平均出发延误时间排降序,并将结果保留在longest delay 表中。把结果展示出来。 (5) 根据出发地 (origin) 在同一个图中画出风速 wind speed (x轴)和出发延误时间 dep delay (y轴) 的平滑曲线图 (6) 根据不同出发地(origin) 在平行的3 个图中画出风速 ind speed(x 轴)和出发延误时间 dep delay(y轴) 的散点图。 (7) 根据 flight weather 表,画出每个月航班数的直方分布图,x 轴为月份,轴是每个月份航班数所占的比例。 (8) 根据 flight weather 表,画出每个月航班距离的 boxplot 图,x轴为月份,y轴为航行距离,根据的航行距离的中位数从低到高对x 轴的月份进行重新排序。 用R语言回答
时间: 2024-03-15 11:47:47 浏览: 138
抱歉,作为一个AI语言模型,我不能直接在本地执行数据操作。但我可以提供相应的R代码,供你参考。
1) 从 flights 数据表中挑选出以下变量: (vear,month,day, hour, origin, dep delay, distance. carrier),将生产的新表保存为 flight1。
```R
flight1 <- flights %>% select(year, month, day, hour, origin, dep_delay, distance, carrier)
```
2) 从 weather 数据表中挑选出以下变量: (year, month, day, hour, origin, humid, wind speed),将生产的新表保存为 weather1。
```R
weather1 <- weather %>% select(year, month, day, hour, origin, humid, wind_speed)
```
3) 将 flight1 表和 weather1 表根据共同变量进行内连接,随机抽取 100000 行数据,将生产的结果保存为 flight_weather。
```R
flight_weather <- inner_join(flight1, weather1, by = c("year", "month", "day", "hour", "origin")) %>% sample_n(100000)
```
4) 从 flight_weather 表中对三个出发机场按照平均出发延误时间排降序,并将结果保留在 longest_delay 表中。把结果展示出来。
```R
longest_delay <- flight_weather %>% group_by(origin) %>% summarize(avg_delay = mean(dep_delay)) %>% arrange(desc(avg_delay))
longest_delay
```
5) 根据出发地 (origin) 在同一个图中画出风速 wind speed (x轴)和出发延误时间 dep delay (y轴) 的平滑曲线图。
```R
ggplot(flight_weather, aes(x = wind_speed, y = dep_delay, color = origin)) + geom_smooth() + labs(x = "Wind Speed", y = "Departure Delay", title = "Wind Speed vs. Departure Delay by Origin")
```
6) 根据不同出发地(origin) 在平行的3 个图中画出风速 ind speed(x 轴)和出发延误时间 dep delay(y轴) 的散点图。
```R
ggplot(flight_weather, aes(x = wind_speed, y = dep_delay)) + geom_point() + facet_wrap(~ origin) + labs(x = "Wind Speed", y = "Departure Delay", title = "Wind Speed vs. Departure Delay by Origin")
```
7) 根据 flight_weather 表,画出每个月航班数的直方分布图,x 轴为月份,轴是每个月份航班数所占的比例。
```R
ggplot(flight_weather, aes(x = month)) + geom_bar() + labs(x = "Month", y = "Proportion of Flights", title = "Flight Distribution by Month")
```
8) 根据 flight_weather 表,画出每个月航班距离的 boxplot 图,x轴为月份,y轴为航行距离,根据的航行距离的中位数从低到高对x 轴的月份进行重新排序。
```R
flight_weather %>% mutate(month = factor(month)) %>% ggplot(aes(x = month, y = distance, fill = month)) + geom_boxplot() + scale_x_discrete(limits = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"), breaks = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")) + labs(x = "Month", y = "Distance", title = "Flight Distance by Month") + theme(legend.position = "none")
```
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)