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?Thanks for the help. -- View this message in context: http://n4.nabble.com/Graphing-a-piece-wise-defined-function-tp1584105p1584105.html Sent from the R help mailing list archive at Nabble.com.
Hi r-help-bounces at r-project.org napsal dne 08.03.2010 05:23:25:> > Hello. I am new to R, and am typing some homework for my undergradAnalysis> class. I am trying to graph the following function in R: f(x) = x^2 forx> >=0, and f(x) = 0 for x <0. How do I do this in R?I would probably use curve function. Regards Petr> > Thanks for the help. > -- > View this message in context:http://n4.nabble.com/Graphing-a-piece-wise-> defined-function-tp1584105p1584105.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
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