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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With