[R] constrain min and max of output

Jim Maas j.maas at uea.ac.uk
Tue Oct 25 14:46:16 CEST 2011


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



More information about the R-help mailing list