Quantcast

Wrap to 360

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Wrap to 360

peter.mills
Hi

Is there an equivalent for R of the Matlab function wrapTo360?

Many thanks
Peter


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Wrap to 360

R help mailing list-2
The key function is '%%' (remainder), but its result needs to be
tweaked at mulitplies of 360 because Matlab's definition of wrapTo360
is

lonWrapped = wrapTo360(lon) wraps angles in lon, in degrees, to the
interval [0 360] such that 0 maps to 0 and 360 maps to 360. (In
general, positive multiples of 360 map to 360 and negative multiples
of 360 map to zero.)

wrapTo360 <- function (lon)
{
    ret <- lon%%360
    ret[lon >= 360 & ret == 0] <- 360
    ret
}

As in:

> wrapTo360(c(-721,-720,-719,-361,-360,-359,-1,0,1,359,360,361,720,721))
 [1] 359   0   1 359   0   1 359   0   1 359 360   1 360   1


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Feb 13, 2017 at 8:44 AM, Peter Mills <[hidden email]> wrote:

> Hi
>
> Is there an equivalent for R of the Matlab function wrapTo360?
>
> Many thanks
> Peter
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Loading...