[R] GPS handling libraries or (String manipulation)
Daniel Nordlund
djnordlund at frontier.com
Wed Mar 7 20:29:43 CET 2012
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Gabor Grothendieck
> Sent: Wednesday, March 07, 2012 8:52 AM
> To: Alaios
> Cc: R help
> Subject: Re: [R] GPS handling libraries or (String manipulation)
>
> On Wed, Mar 7, 2012 at 11:28 AM, Alaios <alaios at yahoo.com> wrote:
> > Dear all,
> > I would like to ask you if R has a library that can work with different
> GPS formats
> >
> > For example
> > I have a string of this format
> >
> > N50° 47.513 E006° 03.985
> > and I would like to convert to GPS decimal format.
> >
> > that means for example converting the part N50° 47.513
> > to 50 + 47/60 + 513/3600.
> >
> > Is it possible to do that with R?
> > What is the name of such a library?
> >
>
> Use strapply to extract the digits and convert them to numeric
> followed by matrix multiplication to apply the formula:
>
> library(gsubfn)
> x <- "N50° 47.513"
>
> c(1, 1/60, 1/3600) %*% strapply(x, "\\d+", as.numeric, simplify = TRUE)
>
>
Isn't 47.513 in the string above just over 47 and one-half minutes? In the calculation above, the .513 minutes is being treated as 513 seconds (I know that is what the OP asked for). Shouldn't the calculation actually be something like this
c(1, 1/60) %*% strapply(x, "\\d+.?\\d+", as.numeric, simplify = TRUE)
If I am wrong, I await correction and apologize in advance for the noise.
Dan
Daniel Nordlund
Bothell, WA USA
More information about the R-help
mailing list