Re: [R] constrain min and max of output

2011-10-25 Thread Vining, Kelly
That is really quite clever! -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Timothy Bates Sent: Tuesday, October 25, 2011 6:03 AM To: Jim Maas Cc: r-help@r-project.org Subject: Re: [R] constrain min and max of output this works

Re: [R] constrain min and max of output

2011-10-25 Thread Eliano
Hi There, I have a similar problem. I have a function that i want to maximize. lets say: (x-2)^2+(y-4)^2 and i want to constraint that maximization to x+y<=5 I can program that constraints in R. Do you have any suggestion? Regards -- View this message in context: http://r.789695.n4.nabble.c

Re: [R] constrain min and max of output

2011-10-25 Thread Duncan Murdoch
On 25/10/2011 9:03 AM, Timothy Bates wrote: this works x=1; y=-100; z = min(5, max(1, x+y)); z But it only works for scalar x and y. The vector version would use pmin() and pmax(). Duncan Murdoch On 25 Oct 2011, at 1:46 PM, Jim Maas wrote: > Hello, > > Is there a simple way/function t

Re: [R] constrain min and max of output

2011-10-25 Thread Timothy Bates
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

[R] constrain min and max of output

2011-10-25 Thread Jim Maas
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 bu