If DF
is the two column data frame corresponding to the data in the question then:
xtabs(data = DF)
which gives:
V2
V1 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
Note: We used this for the input:
DF <- structure(list(V1 = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 3L), .Label = c("User ID 1",
"User ID 2", "User ID 3", "User ID 4", "User ID 5"), class = "factor"),
V2 = structure(c(4L, 1L, 5L, 2L, 3L, 2L, 1L), .Label = c("Artist 1",
"Artist 2", "Artist 3", "Artist 5", "Artist 7"), class = "factor")), .Names = c("V1",
"V2"), class = "data.frame", row.names = c(NA, -7L))