I have a data set that looks like this
lat_deg lat_min long_deg long_min
site 1 44 4.971 80 27.934
site 2
site 3
site 4
site 5
site <- c(1,2,3)
lat_deg <- c(44,44,44)
lat_min <- c(4.971, 4.977, 4.986)
long_deg <- c(80,80,80)
long_min <- c(27.934, 27.977, 27.986)
df <- data.frame(site, lat_deg, lat_min, long_deg, long_min)
How do I convert this into degree decimal only? All my lats are in N and longs in W, so I'm not too worried except the final sign should be correct. Additionally, will I be able to calculate altitude from here?
Note: All other questions on SO focus on DMS to DD. This question has not been asked before.
Based on the data given, here is a approach using dplyr
:
df %>%
mutate(lat = lat_deg + lat_min/60,
long = long_deg + long_min/60)
returns
site lat_deg lat_min long_deg long_min lat long
1 1 44 4.971 80 27.934 44.08285 80.46557
2 2 44 4.977 80 27.977 44.08295 80.46628
3 3 44 4.986 80 27.986 44.08310 80.46643
or simply
df$lat <- df$lat_deg + df$lat_min/60
df$long <- df$long_deg + df$long_min/60