Re: [R] Calculate remainer

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Wed, 19 Dec 2007 06:21:15 -0500

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.

?"%%" to see how to get the remainder. You might put the "result" and remainder together in a function like this:

myfunc <- function(x,y){list(result = floor(x / y), remainder = x %% y)}

myfunc(x=50, y=12)
$result
[1] 4

$remainder
[1] 2

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Wed 19 Dec 2007 - 11:24:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 19 Dec 2007 - 11:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.