《R for data science》练习求助——已解决
来自: 牛牛
《R for data science》chapter 3
题目: For each plane, count the number of flights before the first delay of greater than 1 hour.
标准答案的代码如下:
flights %>%
# sort in increasing order
select
(tailnum, year, month,day, dep_delay) %>%
filter
(!
is.na
(dep_delay)) %>%
arrange
(tailnum, year, month, day) %>%
group_by
(tailnum) %>%
#
cumulative
number of flights delayed over one hour
mutate
(cumulative_hr_delays =
cumsum
(dep_delay > 60)) %>%
# count the number of flights == 0
summarise
(total_flights =
sum
(cumulative_hr_delays < 1)) %>%
arrange
(total_flights)
我自己试图一行一行地运行以后发现,输入最后一行
arrange
(total_flights)后得到的结果中包含的数据跟未输入不一样,arrange()不是应该只是对数据进行排序,为什么会改变包含的数据内容。
结果分别如下:
你的回应
回应请先 登录 , 或 注册相关内容推荐
最新讨论 ( 更多 )
- 组建一个R语言学习群 (xiaoxiao)
- 求代做R语言大作业 有偿!有意者私聊! (豆友gnJKu-wCcw)
- 寻R语言大佬 (南风知我意)
- shiny web (青山)
- 求r语言大佬辅导 (桂花小圆子0o)