\begin{Schunk}
\begin{Sinput}
  dat$grpfac1 <- factor(dat$grp)
  str(dat$grpfac1)
\end{Sinput}
\begin{Soutput}
 Factor w/ 3 levels "1","2","3": 1 2 1 3 1 1 2 2 2 1 ...
\end{Soutput}
\begin{Sinput}
  with(dat, table(grpfac1, grp))
\end{Sinput}
\begin{Soutput}
       grp
grpfac1 1 2 3
      1 6 0 0
      2 0 7 0
      3 0 0 6
\end{Soutput}
\end{Schunk}
