So I've been shared a dataset with what to me is an unusual format for degree min second data.
In their own words:
The coordinates provided are longitude and latitude in degrees minutes and seconds.
So for example, coordinates recorded in the spreadsheet as
X_Long: -10.0135 Y_Lat: 53.5726, can be taken as Longitude: 10º 01'35" W,
Latitude: 53º 57'26" N using standard notation.
I need to get this into decimal. Any quick way to do this ?
Edit:
in trying to solve this I made a following code:
# Fake data
X_Long <- as.numeric(c(-2.4564, -1.0134, -8.01))
long.temp <- abs(X_Long - trunc(X_Long))
long.min <- trunc(long.temp*100)
long.sec <- trunc(as.integer((long.temp*100 - long.min)*100))
Its giving me weird rounding errors:
> X_Long
[1] -2.4564 -1.0134 -8.0100
> long.temp
[1] 0.4564 0.0134 0.0100
> long.min
[1] 45 1 0
> long.sec
[1] 63 34 99
This seems to be coming from the trunc function – compare results here
> long.temp*100
[1] 45.64 1.34 1.00
> trunc(long.temp*100)
[1] 45 1 0
Anyone know why this is happening ?
Best Answer
How about:
The code would be a lot neater without having to find the sign up front and apply it to the sum. (Well I can't see a neater way).
It's vectorized:
You probably want checks for sensible inputs, treating lon/lat separately etc.
Check round-tripping (here we have to separate for lon/lat)