The qdap package has the adjmat
function that can do this:
dat <- read.table(text=gsub(pattern = " --- ", replacement = ",",
"User ID 1 --- Artist 5
User ID 2 --- Artist 1
User ID 3 --- Artist 7
User ID 4 --- Artist 2
User ID 5 --- Artist 3
User ID 1 --- Artist 2
User ID 3 --- Artist 1"),sep=",", stringsAsFactors = FALSE)
library(qdap)
x <- with(dat, termco(V1, V2, unique(V1)))
adjmat(x)$boolean
## > adjmat(x)$boolean
## Artist 1 Artist 2 Artist 3 Artist 5 Artist 7
## User ID 1 0 1 0 1 0
## User ID 2 1 0 0 0 0
## User ID 3 1 0 0 0 1
## User ID 4 0 1 0 0 0
## User ID 5 0 0 1 0 0
PS Tim Riffe Nice approach to reading in the data :)