An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111221/580347d0/attachment.pl>
Gps fraction of degrees function
3 messages · Alaios, Clint Bowman
The following (untested) should get you close: deg<-as.integer(strsplit(coords, "?")[[1]][1]) min<-as.integer(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][1]) sec<-as.numeric(strsplit(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][2], "\"")[[1]][1]) nswe<-strsplit(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][2], "\"")[[1]][2] deg.frac<-((sec/60+min)/60+deg deg.frac<-ifelse(nswe=="S"|nswe=="E",-deg.frac,deg.frac) Clint
Clint Bowman INTERNET: clint at ecy.wa.gov
Air Quality Modeler INTERNET: clint at math.utah.edu
Department of Ecology VOICE: (360) 407-6815
PO Box 47600 FAX: (360) 407-7534
Olympia, WA 98504-7600
USPS: PO Box 47600, Olympia, WA 98504-7600
Parcels: 300 Desmond Drive, Lacey, WA 98503-1274
On Wed, 21 Dec 2011, Alaios wrote:
> Dear all,?? I have the following written example
>
>> coords <- "51?30'48.58\"N"
>>
>> as.integer(strsplit(coords, "?")[[1]][1])
> [1] 51
>> as.integer(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][1])
> [1] 30
>> as.numeric(strsplit(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][2], "\"")[[1]][1])
> [1] 48.58
>> strsplit(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][2], "\"")[[1]][2]
> [1] "N"
>
>
> My code gets from the coords degrees , minutes, seconds and finally the N/S/W/E
>
> Could you please tell me if there is any function in R that can convert all the above into fractions of degrees (single numerical value).
>
> B.R
> Alex
>
> [[alternative HTML version deleted]]
>
>
I see my pre-coffee fingering hit an incorrect key in the final line--"E" is positive, "W" is negative.
Clint Bowman INTERNET: clint at ecy.wa.gov
Air Quality Modeler INTERNET: clint at math.utah.edu
Department of Ecology VOICE: (360) 407-6815
PO Box 47600 FAX: (360) 407-7534
Olympia, WA 98504-7600
USPS: PO Box 47600, Olympia, WA 98504-7600
Parcels: 300 Desmond Drive, Lacey, WA 98503-1274
On Wed, 21 Dec 2011, Clint Bowman wrote:
> The following (untested) should get you close:
>
> deg<-as.integer(strsplit(coords, "?")[[1]][1])
> min<-as.integer(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][1])
> sec<-as.numeric(strsplit(strsplit(strsplit(coords, "?")[[1]][2],
> "'")[[1]][2], "\"")[[1]][1])
> nswe<-strsplit(strsplit(strsplit(coords, "?")[[1]][2], "'")[[1]][2],
> "\"")[[1]][2]
>
> deg.frac<-((sec/60+min)/60+deg
> deg.frac<-ifelse(nswe=="S"|nswe=="E",-deg.frac,deg.frac)
>
> Clint
>
>