\begin{Schunk}
\begin{Sinput}
 nes2002$democ <- ifelse(nes2002$partyid == "D", 1, 0)
 table(nes2002$democ, nes2002$partyid, exclude = NULL)
\end{Sinput}
\begin{Soutput}
         I   D   R <NA>
  0    429   0 474    0
  1      0 502   0    0
  <NA>   0   0   0  106
\end{Soutput}
\begin{Sinput}
 nes2002$repub <-ifelse(nes2002$partyid == "R", 1, 0)
 table(nes2002$repub, nes2002$partyid, exclude = NULL, dnn = list("repub", "partyid"))
\end{Sinput}
\begin{Soutput}
      partyid
repub    I   D   R <NA>
  0    429 502   0    0
  1      0   0 474    0
  <NA>   0   0   0  106
\end{Soutput}
\end{Schunk}
