[R] Plotting a function that includes logical operators

dean123 christopher_dean_123 at yahoo.co.uk
Wed Jul 27 09:01:36 CEST 2011


I am trying to plot the following function over the range 0-100

test <- function(t){{
if (t<=10)
x<-t*0
else x<-2*t
}
x
}

when I use plot(test,0,100) the GUI produces the following;

"Warning message:
In if (t <= 10) x <- t * 0 else x <- 2 * t :
  the condition has length > 1 and only the first element will be used"

I am confused as when I evaluate the function for individual t it gives the
correct response i.e. 0 for t<=10 and 2*t for t>10... This is what I wish
the function to do however, I am not able to plot the function.

Any help would be most appreciated!


--
View this message in context: http://r.789695.n4.nabble.com/Plotting-a-function-that-includes-logical-operators-tp3697732p3697732.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list