# Vincenty Sphere Great Circle Distance in R (Example)

In this R tutorial you’ll learn how to calculate the Vincenty sphere great circle distance.

The post will contain this:

It’s time to dive into the example…

## Creation of Example Data

The first step is to create some example data:

```my_points <- matrix(c(81.25798, 73.81277,    # Create longitude/latitude matrix
14.91254, 18.18145),
nrow = 2)
colnames(my_points) <- c("longitude", "latitude")
rownames(my_points) <- c("pt_1", "pt_2")
my_points                                    # Print longitude/latitude matrix``` Table 1 illustrates the output of the RStudio console and visualizes that our example data has two rows and two columns. Each row represents the longitude and latitude of one geospatial data point.

## Example: Calculate Vincenty Sphere Great Circle Distance Using distVincentySphere() Function of geosphere Package

This example shows how to return the Vincenty sphere distance in R using the distVincentySphere of the geosphere package.

If we want to use the commands and functions of the geosphere package, we first need to install and load geosphere:

```install.packages("geosphere")                # Install geosphere package

After running the previous R code, we can apply the distVincentySphere function to calculate the Vincenty sphere great circle distance in R:

```my_dist <- distVincentySphere(my_points)     # Calculate Vincenty sphere distance
my_dist                                      # Print Vincenty sphere distance
#  873680.6```

The geospatial distance between our two data points is 873680.6 according to the Vincenty sphere formula.

## Video, Further Resources & Summary

Do you need further explanations on the examples of this article? Then you could watch the following video of my YouTube channel. I show the content of this article in the video:

Furthermore, you may have a look at the other tutorials on my website. Some articles about distance measures are listed below.

To summarize: This post has shown how to compute the geospatial Vincenty sphere distance in the R programming language. Please let me know in the comments section, in case you have further comments or questions.

Subscribe to the Statistics Globe Newsletter