[R] Calculate remainer
m_olshansky at yahoo.com
Fri Dec 21 00:23:56 CET 2007
This is OK if the ratio is positive, but for -50
divided by 12 the floor is -5 and the remainder is 10
(and not -4 and -2 as one may want). By the way, using
%% and %/% leads to same result.
Using trunc will remedy the situation, i.e.
> x <- -50
> y <- 12
> a <- trunc(x/y)
> r <- x - a*y
--- Julian Burgos <jmburgos at u.washington.edu> wrote:
> Hi Livia,
> There are several ways to do this. Try:
> floor(a) will give you the entire portion, and
> a-floor(a) will give you the remainder.
> livia wrote:
> > Hello everyone,
> > I have got a question about a simple calculation.
> If I would like to
> > calculate 50/12 and return the result as 4 and the
> remainer 2. Is there a
> > function of doing this?
> > Many thanks.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained,
> reproducible code.
More information about the R-help