If you have latitude and/or longitude data in sexagesimal degrees, in the form degreesº minutes’ seconds” hemisfere (e.g. 41° 34′ 10.956″ N or 8° 37′ 47.1036″ W, with or without spaces in between), the *dms2dec* function can convert them to decimal degrees, which are usually required for mapping. This function is **not included in a package**, but it’s in the “**Supporting Information**” of** Zanolla et al. (2018)**, so **please cite** this paper if you use the function.

dms2dec <- function(dms, separators = c("º", "°", "\'", "\"")) {
# version 1.0 (25 Sep 3013)
# dms: a vector (or column) of latitude or longitude in degrees-minutes-seconds-hemisfere, e.g. 41° 34' 10.956" N (with or without spaces)
# separators: the characters that are separating degrees, minutes and seconds in dms
dms <- as.character(dms)
dms <- gsub(pattern = " ", replacement = "", x = dms)
for (s in separators) dms <- gsub(pattern = s, replacement = "_splitHere_", x = dms)
splits <- strsplit(dms, split = "_splitHere_")
n <- length(dms)
deg <- min <- sec <- hem <- vector("character", n)
for (i in 1:n) {
deg[i] <- splits[[i]][1]
min[i] <- splits[[i]][2]
sec[i] <- splits[[i]][3]
hem[i] <- splits[[i]][4]
}
dec <- as.numeric(deg) + (as.numeric(min) / 60) + (as.numeric(sec) / 3600)
sign <- ifelse (hem %in% c("N", "E"), 1, -1)
dec <- sign * dec
return(dec)
} # end dms2dec function

[presented with Pretty R]

Usage example, from a table called *mydata*:

mydata$latitude.decimal <- dms2dec(mydata$Latitude)

mydata$longitude.decimal <- dms2dec(mydata$Longitude)

**REFERENCES:**

Zanolla M., Altamirano M., Carmona R., De La Rosa J., Souza-Egipsy V., Sherwood A., Tsiamis K., Barbosa A.M., Muñoz A.R. & Andreakis N. (2018) Assessing global range expansion in a cryptic species complex: insights from the red seaweed genus *Asparagopsis* (Florideophyceae). *Journal of Phycology*, 54: 12-24

### Like this:

Like Loading...

*Related*

Is this paper published already? Thank you! very useful function!

No, the paper’s still being reviewed back and forth… Good to know the function’s useful, though! Cheers

Hey! The paper’s just been accepted – please find the updated reference at the bottom of this post. Cheers

Awesome! Congratulations!! And thank you for sending the link!

Hi! The paper is now definitely published with volume and page numbers — see bottom of the post above. Cheers