简体   繁体   English

"如何找到差异的最小值和最大值"

[英]How to Find the min and the max of diff

There is a data frame already given called taxis, now I have to do the following,but I am stuck on the last step...已经给出了一个名为出租车的数据框,现在我必须执行以下操作,但我被困在最后一步......

# Create my_distance and diff # 创建 my_distance 和 diff

taxis_my_dist <- taxis  %>% 
  mutate(my_distance = hav_dist(pickup_longitude , pickup_latitude ,dropoff_longitude, dropoff_latitude ),
         diff = trip_distance-my_distance)

# Find the min and the max of diff # 找出 diff 的最小值和最大值

max(taxis[,diff])
min(diff)

Create my_distance and diff创建 my_distance 和 diff

taxis_my_dist <- taxis  %>% 
  mutate(my_distance = hav_dist(pickup_longitude , pickup_latitude ,dropoff_longitude, dropoff_latitude ),
         diff = trip_distance-my_distance)

Find the min and the max of diff找出 diff 的最小值和最大值

max(taxis_my_dist$diff)
min(taxis_my_dist$diff)

Almost there!差不多好了!

library(dplyr)

taxis  %>% 
mutate(my_distance = hav_dist(pickup_longitude , pickup_latitude ,dropoff_longitude, dropoff_latitude ),
     diff = trip_distance-my_distance) %>%
summarise(
max = max(diff)
min = min(diff)    
)

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

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