You can easily create a matrix of 0's where number of rows is same as index and number of columns is the maximum value in index. We could then create a row, column matrix using row function as row index and index values as column index and turn them to 1.
mat <- matrix(0, ncol = max(index, na.rm = TRUE), nrow = nrow(index))
mat[cbind(c(row(index)), c(index))] <- 1
mat
# [,1] [,2] [,3] [,4] [,5]
#[1,] 1 0 1 0 0
#[2,] 1 1 0 0 0
#[3,] 1 0 1 0 0
#[4,] 1 0 1 0 1
#[5,] 1 0 0 1 1
#[6,] 0 1 0 0 0
#[7,] 0 0 1 1 0
data
index <- structure(c(1, 1, 1, 1, 1, 2, 3, NA, 2, 3, 3, 4, NA, 4, 3, NA,
NA, 5, 5, NA, NA), .Dim = c(7L, 3L))