\Header{stepfun}{Step Functions}
\alias{is.stepfun}{stepfun}
\alias{print.stepfun}{stepfun}
\alias{summary.stepfun}{stepfun}
\alias{knots}{stepfun}
\alias{knots.stepfun}{stepfun}
\keyword{iplot}{stepfun}
\begin{Usage}
\begin{verbatim}
fn <- stepfun(x, y, f=0)
is.stepfun(fn)
knots(fn)
plot(fn, ...)
print(fn, ...)
summary(fn)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] numeric vector giving the ``knots'' or jump locations of the
step function.
\item[\texttt{y}] numeric vector one longer than \texttt{x}, giving the heights of
the function values \emph{between} the x values.
\item[\texttt{f}] a number between 0 and 1, indicating how interpolation outside
the given x values should happen.  See  \texttt{\Link{approxfun}}.
\item[\texttt{fn}] an \R\ object inheriting from \texttt{"stepfun"}.
\end{ldescription}
\end{Arguments}
\begin{Description}
Given the vectors \eqn{(x_1,\ldots, x_n)}{(x[1],\ldots, x[n])} and
\eqn{(y_0,y_1,\ldots, y_n)}{(y[0],y[1],\ldots, y[n])}  (one value more!),
\texttt{stepfun(x,y,...)} returns an interpolating ``step'' function,
say \texttt{fn}. I.e., \eqn{fn(t) = c}{}\eqn{_i}{[i]} (constant) for
\eqn{t \in (x_i, x_{i+1})}{t in ( x[i], x[i+1])} and
\eqn{fn(x_i) = y_i}{fn(x[i]) = y[i]} for \eqn{i=1,\ldots,n}{}.

The value of the constant \eqn{c_i}{c[i]} above depends on the
``continuity'' parameter \texttt{f}.
For the default, \texttt{f = 0}, \texttt{fn} is a ``cadlag'' function, i.e.
continuous at right, limit (``the point'') at left.
In general, \eqn{c_i}{c[i]} is interpolated in between the
neighbouring \eqn{y}{} values,
\eqn{c_i= (1-f) y_i + f\cdot y_{i+1}}{c[i] = (1-f)*y[i] + f*y[i+1]}.
Therefore, for non-0 values of \texttt{f}, \texttt{fn} may no longer be a proper
step function, since it can be discontinuous from both sides.\end{Description}
\begin{Value}
A function of class \texttt{"stepfun"}, say \texttt{fn}.
There are methods available for
summarizing (\texttt{"summary(.)"}), representing
(\texttt{"print(.)"}) and plotting  (\texttt{"plot(.)"}, see
\texttt{\Link{plot.stepfun}}) \texttt{"stepfun"} objects.

The \texttt{\Link{environment}} of \texttt{fn} contains all the
information needed;
\ \ \texttt{"x","y"}: the original arguments;
\ \ \texttt{"n"}: number of knots (x values);
\ \ \texttt{"f"}: continuity parameter;
\ \ \texttt{"yleft", "yright"} the function values \emph{outside} the knots;
\ \ \texttt{"method"} (always \texttt{== "constant"}; not used, from
\texttt{\Link{approxfun}(.)}).
The knots are also available by \texttt{\Link{knots}(fn)}.\end{Value}
\begin{Author}
Martin Maechler, \email{maechler@stat.math.ethz.ch} with some basic
code from Thomas Lumley.\end{Author}
\begin{SeeAlso}
\texttt{\Link{ecdf}} for empiricial distribution functions as
special step functions and \texttt{\Link{plot.stepfun}} for \emph{plotting}
step functions.

\texttt{\Link{approxfun}} and \texttt{\Link{splinefun}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
y0 <- c(1,2,4,3)
sfun0  <- stepfun(1:3, y0, f = 0)
sfun.2 <- stepfun(1:3, y0, f = .2)
sfun1  <- stepfun(1:3, y0, f = 1)
sfun0
summary(sfun0)
summary(sfun.2)

x0 <- seq(0.5,3.5, by = 0.25)
rbind(x=x0, f.f0 = sfun0(x0), f.f02= sfun.2(x0), f.f1 = sfun1(x0))
\end{ExampleCode}
\end{Examples}

