[R] defining a function by branches

Duncan Murdoch murdoch at stats.uwo.ca
Thu Oct 14 22:33:38 CEST 2004

On Thu, 14 Oct 2004 23:24:40 +0300, Pedro Rodrigues de Almeida
<pmrdealmeida at mac.com> wrote :

>Hi there,
>How can I plot a function in R which is defined by conditional 
>branches?, e.g.:
>u(x) = 1, Ed<x<2Ed (where Ed is a positive constant, say, 25);
>u(x)=0.5*x, x>2Ed

ifelse(x < 2*Ed, 1, 0.5*x)

is close to what you want (but I'm not sure what you want for x < Ed).

Duncan Murdoch

More information about the R-help mailing list