[R] Geocode Conversion

arun smartpink111 at yahoo.com
Wed Oct 23 14:32:52 CEST 2013


Hi,
Try:

x$Log <-  gsub("^(\\d{2})(\\d{2})\\.(\\d{3})","\\1:\\2:\\3E",sprintf("%.3f",x$Log))
x$lat <- gsub("^(\\d{1})(\\d{2})\\.(\\d{3})","\\1:\\2:\\3S",sprintf("%.3f",x$lat))
 x
#         Log       lat
#1 30:25:264E 9:01:331S
#2 30:39:237E 8:10:811S
#3 31:37:760E 8:06:040S
#4 31:41:190E 8:06:557S
#5 31:41:229E 8:06:622S
#6 31:38:891E 8:06:281S

A.K.


On Wednesday, October 23, 2013 5:07 AM, Peter Maclean <pmaclean2011 at yahoo.com> wrote:
I have this kind od  data
x <- read.table(text="
  Log     lat
3025.264 901.331
3039.237 810.811
3137.760 806.040
3141.190 806.557
3141.229 806.622
3138.891 806.281",
                header=TRUE,
stringsAsFactors=FALSE)
I what to insert “:” after every first
two numbers in Lon variable and after 
every first number in lat variable.
The variables should end with “E”  for
Lon and “S” for the Lon variable.  The
results should look like:
Lon                      Lat
30:25:264E        9:01:331S
30:39:237E        8:10:811S
31:37:760E        8:06:040S
31:41:190E        8:06:557S
31:41:229E        8:06:622S
31:38:891E        8:06:281S 
I am using gmt package for
geocodes conversion.
I will appreciate any help.

Peter Maclean
Department of Economics
UDSM
    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list