Re: [R] Simple question regarding domain restrictions/piecewise functions in R

2012-03-26 Thread chad.mills
Yes! Thanks. It was just the "NA" value instead of the "as.null" that does the trick. Correct code for the original piecewise I stated (for those who might be looking later) is: f <- function(x){ ifelse((-1 < x & x < 1),x^2,ifelse((2http://r.789695.n4.nabble.com/Simple-questio

Re: [R] Simple question regarding domain restrictions/piecewise functions in R

2012-03-26 Thread Rolf Turner
Does f <- function(x){ ifelse((-1 < x & x < 1) | (2 < x & x < 3),x^2,NA) } plot(f,xlim=c(-3,5)) give you what you want? cheers, Rolf Turner On 26/03/12 11:08, chad.mills wrote: I am a novice R user. I would like to be able to graph some simple

[R] Simple question regarding domain restrictions/piecewise functions in R

2012-03-25 Thread chad.mills
I am a novice R user. I would like to be able to graph some simple piecewise functions/functions with domain restrictions in R, but I'm having trouble defining such functions. For example, I would like to define the following function: f(x)={x^2 if -1http://r.789695.n4.nabble.com/Simple-question