[R] GPS handling libraries or (String manipulation)

Gabor Grothendieck ggrothendieck at gmail.com
Wed Mar 7 20:41:02 CET 2012


On Wed, Mar 7, 2012 at 2:29 PM, Daniel Nordlund <djnordlund at frontier.com> wrote:
>> -----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 that's it then the regular expression could also be written as:  "[0-9.]+"


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list