Попробуйте:
df = data.frame(let = LETTERS[1:12],
vert = c(10, 10, 2.5, 5, 10, 5, 2.5, 10, 1.25, 1.25, 1.25, 1.25),
hor = c(2,2,3,2,4,2,3,4,1,4,4,1),
stringsAsFactors = F)
# find unique combinations
positions = expand.grid(unique(df$vert), unique(df$hor))
# pre-allocate matrix
M = matrix(ncol = length(unique(df$hor)),
nrow = length(unique(df$vert)))
rownames(M) <- sort(unique(df$vert))
colnames(M) <- sort(unique(df$hor))
# loop over valid positions and put them in the matrix
for (i in c(1:nrow(positions))){
# get row
row = as.numeric(positions[i,])
# gather all entries that go in position
valid = df[df$vert == row[1] & df$hor == row[2], 'let']
valid = paste(valid, collapse=",")
# get matrix indices
vert_i <- which(rownames(M) == row[1])
horiz_i <- which(colnames(M) == row[2])
# put the data in the matrix
M[vert_i, horiz_i] <- valid
}
print(M)
Это может быть более эффективным, но оно выполняет свою работу.