[R] Graphing a piece-wise defined function

Karl Ove Hufthammer karl at huftis.org
Mon Mar 8 12:55:11 CET 2010


On Sun, 7 Mar 2010 20:23:25 -0800 (PST) thedoctor81877 <thedoctor81877
@gmail.com> wrote:
> Hello. I am new to R, and am typing some homework for my undergrad Analysis
> class. I am trying to graph the following function in R: f(x) = x^2 for x
> >=0, and f(x) = 0 for x <0. How do I do this in R?

f=function(x) ifelse(x >= 0, x^2, 0)
curve(f, -2, 4)

-- 
Karl Ove Hufthammer



More information about the R-help mailing list