[R] Plot step function

David Winsemius dwinsemius at comcast.net
Sat Feb 6 19:23:12 CET 2016


> On Feb 6, 2016, at 4:11 AM, jupiter <jupiter.hce at gmail.com> wrote:
> 
> Hi,
> 
> I am just starting to learn R, sorry for asking a simple question. How can
> plot a line x <= 0 y = 0, x > 0 y = 1?

There is a stepfun function and an associated plotting method:

 y0 <- c(rep(0,3),rep(1,3))
 sfun0  <- stepfun(-2:2, y0, right=TRUE)
 plot(sfun0)
 
-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list