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 <peter.mi...@strath.ac.uk> wrote: > Hi > > Is there an equivalent for R of the Matlab function wrapTo360? > > Many thanks > Peter > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. ______________________________________________ R-help@r-project.org 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.