You can do this pretty easily with some rep
and c
work:
out <- data.frame(X = rep(colnames(conf), each = nrow(conf)),
S = rep(rownames(conf), ncol(conf)),
CONF = c(conf), P = c(P))
out
# X S CONF P
# 1 1 A 0.1 1
# 2 1 B 0.2 1
# 3 1 C 0.3 1
# 4 2 A 0.4 2
# 5 2 B 0.9 3
# 6 2 C 0.3 1
# 7 3 A 0.9 1
# 8 3 B 0.9 3
# 9 3 C 0.4 1
@Thomas had a similar approach (but one which matches the answer you show in your question). His answer looked like this:
cbind.data.frame(X = rep(colnames(conf), each=nrow(conf)),
S = rep(rownames(conf), times=nrow(conf)),
CONF = matrix(t(conf), ncol=1),
P = matrix(t(P), ncol=1))