The location can be input in two different formats, as latitude and longitude in a character string, e.g. for Frankfurt airport as '50 02 00N, 08 34 14E', or as a numerical two-vector in degrees (not radians).

You could then calculate haversine() for all combinations kept in a data frame, for example:

for exmple if ihave the data "quaks" each earthquaks have its own lattitude and longatuide how do i use this function ? im suppost to creat anew data frame or something ?

idid try to add with mutate new colunm that will calculate but the HARVESTIN said i put worng cordinat format , can you show me example ? i mean how do i put it in mutate

Using a small subset of your data, could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

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.

attach(quakes)
library(pracma)
#> Warning: package 'pracma' was built under R version 3.5.3
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
x=mutate(quakes,dist=haversine(quakes$lat,quakes$long))
#> Error in mutate_impl(.data, dots): Evaluation error: Coordinate input not in correct format..

^{Created on 2019-03-19 by the reprex package (v0.2.1)}

If you look at the documentation for the haversine() function (linked above, and can also be seen by running ?haversine when pracma is attached, you'll see that the first two arguments, loc1 and loc2 each take a specific format.

Haversine formula to calculate the arc distance between two points on earth (i.e., along a great circle).

Usage

haversine(loc1, loc2, R = 6371.0)

Arguments

loc1, loc2

Locations on earth; for format see Details. R

Average earth radius R = 6371 km, can be changed on input.

Details

The Haversine formula is more robust for the calculating the distance as with the spherical cosine formula. The user may want to assume a slightly different earth radius, so this can be provided as input.

The location can be input in two different formats, as latitude and longitude in a character string, e.g. for Frankfurt airport as '50 02 00N, 08 34 14E', or as a numerical two-vector in degrees (not radians).

Here for latitude 'N' and 'S' stand for North and South, and for longitude 'E' or 'W' stand for East and West. For the degrees format, South and West must be negative.

These two formats can be mixed.

The data you have given it is not in that format. You're giving it latitude for loc1 and longitude for loc2.

The two possible formats are shown in the example for haversine():

library(pracma)
FRA = '50 02 00N, 08 34 14E' # Frankfurt Airport
ORD = '41 58 43N, 87 54 17W' # Chicago O'Hare Interntl. Airport
fra <- c(50+2/60, 8+34/60+14/3600)
ord <- c(41+58/60+43/3600, -(87+54/60+17/3600))
dis <- haversine(FRA, ORD) # 6971.059 km
fprintf('Flight distance Frankfurt-Chicago is %8.3f km.\n', dis)
#> Flight distance Frankfurt-Chicago is 6971.059 km.
dis <- haversine(fra, ord)
fprintf('Flight distance Frankfurt-Chicago is %8.3f km.\n', dis)
#> Flight distance Frankfurt-Chicago is 6971.059 km.

^{Created on 2019-03-19 by the reprex package (v0.2.1)}

I think haversine() is not vectorized, (I hadn't used the pracma package until responding to you here), so you might need to use purrr, rather than just mutate(). The Stack Overflow thread below should help, they're using a different package, but the same approach should work:

i dont have to use the pcarma it was just a reccomendation that iget from the asseigment , i can use other methods if possible , i want to try to do what have you done but what does %>% mean? sorry im noob

ty i get it now , but i think i need to use pracma becuse ineed to add the calculation as new colum in the quakes data and i cant do it with the method use used

locations <-
quakes %>%
head() %>%
select(long, lat) %>%
mutate(long = if_else(condition = (long > 180),
true = (long - 360),
false = long))
#> Error in quakes %>% head() %>% select(long, lat) %>% mutate(long = if_else(condition = (long > : could not find function "%>%"
distm(x = locations,
fun = distHaversine)
#> Error in distm(x = locations, fun = distHaversine): could not find function "distm"
quakes_distance=mutate(quakes,distance=distm(x = locations,
fun = distHaversine))
#> Error in mutate(quakes, distance = distm(x = locations, fun = distHaversine)): could not find function "mutate"

^{Created on 2019-03-19 by the reprex package (v0.2.1)}

The only problem with the above (as far as I can see yet), it contains some useless rows. Since distance is symmetric, \binom{n}{2} rows are expected, but here we have n^2 rows. Certainly, calculating distances between same locations is not required, and neither are the rows calculating distances between B and A, if we already calculated that between A and B.

But I can't provide a solution to that. I'm sure it's something very trivial, but I fail to spot it. I'm sure someone else will provide a better solution taking care of this.

Most probably, you've already figured out how to avoid the extra rows by now. But to make this thread complete (and for my own satisfaction), I'm posting a solution based on the following post:

wow ty , until now icoudnt get it right and you solve it
although idont know how to add the new colun distance to orignal quakes data i dont think that possiable