[R] Changing sign on absolute numbers 0 problems

Keith Jewell k.jewell at campden.co.uk
Thu Oct 21 12:22:32 CEST 2010


"Sadz A" <sadz_a1000 at yahoo.co.uk> wrote in message 
news:419230.77523.qm at web24610.mail.ird.yahoo.com...
> Hi,
>
> I am trying to do some calculations turning DMS data to decimal degrees 
> using
> the formula (D+(M/60)+(S/3600)), some of the D's involve -ve numbers, the
> easiest way to do the calculation is to use absolute numbers then use the 
> 'sign'
> function in R to change the answer back to the correct -ve or +ve,
>
> for example, if;
> D<--69
> M<-8
> S<-10
> then
> decimal<-D+(M/60)+(S/3600)
> -69+(8/60)+(10/3600)   = this would equal -68.86389  (which is wrong, it 
> should
> be -69.13611,  so i used the following function)
>
> decimal<-(abs(D)+(M/60)+(S/3600))
> decimal.degs<-sign(D)*decimal
> decimal.degs
> -69.13611
>
> because ((69+(8/60)+(10/3600)=69.13611) and then the -sign is put back in.
>
> This works fine untill D=0
> because then 'sign' does not give 0 a +ve sign it takes it as 0 and 
> multiplies
> decimal by 0 to give 0.
> example
> D<-0
> decimal<-D+(M/60)+(S/3600)
> decimal.degs<-sign(D)*decimal
> decimal.degs
> 0
>
> Is there anyway to get around this??????????
> and make D=0 a positive and not a 0 with sign or another function??????
>
> Any help is appreciated
> Thank you
> sadz
>
> ps please email me if you need more info
>
>
>
>
> [[alternative HTML version deleted]]
>
In addition to the other comments, you might be interested in package 'sp' 
which has:
Class "DMS" for degree, minute, decimal second values
and facilities to convert between DMS, decimal, and character.

HTH

Keith J



More information about the R-help mailing list