[R] constrain min and max of output
Vining, Kelly
Kelly.Vining at oregonstate.edu
Tue Oct 25 18:19:28 CEST 2011
That is really quite clever!
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Timothy Bates
Sent: Tuesday, October 25, 2011 6:03 AM
To: Jim Maas
Cc: r-help at r-project.org
Subject: Re: [R] constrain min and max of output
this works
x=1; y=-100;
z = min(5, max(1, x+y));
z
On 25 Oct 2011, at 1:46 PM, Jim Maas wrote:
> Hello,
>
> Is there a simple way/function to constrain the minimum and maximum value of an output from an assignment?
>
> if I have
>
> z <- x +y
>
> but I want z to always be between 1 and 5, such that z=5 if (x+y >= 5) and z=1 if (x+y <= 1).
>
> I know it sounds simple, I can do it with "if" statements but just wondered if there is a simpler way?
>
> Thanks a bunch,
>
> J
>
> ----------------------
>
> Jim Maas
> University of East Anglia
>
> ______________________________________________
> 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.
______________________________________________
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.
More information about the R-help
mailing list