Edx course problem - creating new column, applying function


Creating columns II

Now you're interested in seeing how much distance having to drive along roads (as opposed to in a straight line) adds to trips.

The function hav_dist() , which computes distance using the Haversine formula, has been defined for you. This function takes the longitude of the origin, the latitude of the origin, the longitude of the destination, and the latitude of the destination, in that order.

  • Use the function hav_dist() to create the column my_distance .

  • Create the column diff which is the difference between my_distance and trip_distance .

  • Find the minimum and the maximum of the diff column.


Create my_distance and diff

taxis_my_dist <- taxis %>%
mutate(my_distance = ___,
diff = ___)

Find the min and the max of my_distance


Hi @ravi.dabas07 ,

Just a reminder about the community's homework policy:


Hi Martin
This is not a Home work Question. I am learning R myself through an online course and have nobody to ask questions. I came across this question and really got struck. Without answering this question I can't proceed further.
Appreciate if you can help or guide towards any site where I can solve this problem



I appreciate it's an online course, but the pointers in the homework link still apply. In particular, points 1 and 3 at the bottom of the link.

If you post a reproducible example, then you will have a much better chance of somebody being able to help you.


As @martin.R mentioned above, we'll need you to provide some sort of reproducible example to have enough information to help you.

Could you please turn this into a self-contained reprex (short for reproducible example) with what you've tried thus far?

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ, linked to below.


This was the answer. Had a lot of issues with hav_dist calculating all rows to 0. Hit the button to show me the answer and it was exactly what I had typed out.

Create my_distance and diff

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

Find the min and the max of my_distance