I have the following structure to my dataset
dms_long dms_lat
[1,] "1 3° 41' 19.9\" W" "1 40° 25' 35.8\" N"
[2,] "2 3° 47' 42.2\" W" "2 40° 26' 28.4\" N"
[3,] "3 3° 41' 11.7\" W" "3 40° 28' 39.8\" N"
[4,] "4 " "4 "
[5,] "5 3° 55' 29.6\" W" "5 38° 59' 15.0\" N"
I am trying to convert it so that it follows the following structure;
dms_long dms_lat
1: 3° 41' 19.9" W 40° 25' 35.8" N
2: 3° 47' 42.2" W 40° 26' 28.4" N
3: 3° 41' 11.7" W 40° 28' 39.8" N
4:
5: 3° 55' 29.6" W 38° 59' 15.0" N
I am trying to remove the \
and the first and last "
which should give me 38° 59' 15.0" N
but cannot seem to get this format using gsub
. If anybody has any idea I would appreciate it.
EDIT: Cannot seem to get the following code to run correctly which is why I thought I had errors in formatting.
pts <- cbind(dms_long, dms_lat)
pts <- sub("^\\d+\\s+", "", pts)
pts[pts==""] <- NA
pts <- pts[complete.cases(pts),]
pts <- matrix(as.numeric(sp::char2dms(as.vector(pts), "°")), ncol=2)