Convert 2 columns dataframe to a 2 dimensional matrix in R

dataframe, matrix, r

Solution

DF <- read.table(text="name  work 
one   test1
one   test2
two   test1
two   test3
three test3", header=TRUE)

table(DF)

       work
name    test1 test2 test3
  one       1     1     0
  three     0     0     1
  two       1     0     1

Problem

Hi I am trying to convert an R dataframe with 2 character columns to a matrix. Here is an example of what I am trying to do: suppose I have this dataframe: ``` name work one test1 one test2 two test1 two test3 three test3 ``` And I would like to turn it into this matrix ``` name test1 test2 test3 one 1 1 0 two 1 0 1 three 0 0 1 ``` Any idea how I can accomplish this in R please?

Original source