The if and ifelse commands
The "if" statement is used to conditionally execute statements.\\
The "ifelse" statement conditionally replaces elements of a structure.\\
Examples
\begin{xmpl}
If we want to compute $x^x$ for $x$-values in the range 0 through 5, we can use\\
\begin{lstlisting}
xlist<-seq(0,5,0.01)
y<-NULL
for(x in xlist){
if(x==0){
y<-c(y,1)
}else{
y<-c(y,x**x)
}
}
\end{lstlisting}
\end{xmpl}
\begin{xmpl}
\begin{lstlisting}
x<-seq(0,5,0.01)
y<-ifelse(x==0,1,x^x)
\end{lstlisting}
\end{xmpl}
\begin{xmpl}
\begin{lstlisting}
dat<-read.table ("file")
dat<-ifelse (dat==0,0.01,dat)
\end{lstlisting}
\end{xmpl}
\begin{xmpl}
\begin{lstlisting}
x<-ifelse (is.na(x),0,x)
\end{lstlisting}
\end{xmpl}