\begin{Schunk}
\begin{Sinput}
 xnew <- as.numeric(levels(xf2))[xf2]
 xnew
\end{Sinput}
\begin{Soutput}
[1] 1 2 1 2 2 7
\end{Soutput}
\begin{Sinput}
 table(xnew, x)
\end{Sinput}
\begin{Soutput}
    x
xnew 1 2 7
   1 2 0 0
   2 0 3 0
   7 0 0 1
\end{Soutput}
\end{Schunk}
