\begin{Schunk}
\begin{Sinput}
 dat$w6 <- mapvalues(dat$w2, from = names(newvals), to = newvals)
 table(dat$w6, dat$w5)
\end{Sinput}
\begin{Soutput}
         John Paul George Ringo Erik
  John      8    0      0     0    0
  Paul      0   14      0     0    0
  George    0    0      8     0    0
  Ringo     0    0      0    13    0
  Erik      0    0      0     0    5
\end{Soutput}
\end{Schunk}
