# loop through the observations of dat
for(i in seq_len(nrow(dat))) {
# convert reference ids to integer and store in a vector
# example data requires this step, you may already have integers in your actual data
ref <- as.integer(strsplit(as.character(dat$id_reférence[i]), ",")[[1]])
# loop through the list of references
for(j in ref) {
# mark the citations using (row, column) ~ (i, j) pairs
expected[dat$id_paper[i], j] <- 1
}
}
expected
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
# [1,] 0 1 0 0 0 0 0 0 0 0
# [2,] 0 0 0 1 0 0 0 1 0 0
# [3,] 1 0 0 0 1 0 0 0 0 0
# [4,] 0 0 0 0 0 0 0 1 0 0
# [5,] 0 0 0 1 1 0 0 0 1 0
# [6,] 0 0 1 0 0 0 0 1 0 0
# [7,] 0 1 0 1 0 0 0 0 0 0
# [8,] 0 0 0 0 0 1 0 0 1 0
# [9,] 0 0 0 0 0 0 0 0 0 1
# [10,] 1 0 0 1 0 0 0 0 1 0