Skip to content
Prev 173297 / 398506 Next

Converting a dataframe to a matrix

xtabs is your friend:

xtabs(likes ~ color + name, data=dat)

       color
name    blue green red
  jake     1     1   0
  sally    1     1   0
  tom      0     0   1

See ?xtabs for more info. Note that I changed the "likes?" column to
just "likes". It is a bad idea to have question marks in variable names.

Simon.
On Wed, 2009-03-11 at 01:42 -0400, Jennifer Brea wrote: