data = rbind(c("가", "나", 1),c("가", "다", 3),c("가", "라", 2),c("나", "다", 3),c("나", "라", 1),c("다", "라", 2))

uniq = sort(unique(c(data[,1], data[,2])))

res_mat = matrix(0, length(uniq), length(uniq))
dimnames(res_mat)[[1]] = uniq
dimnames(res_mat)[[2]] = uniq

for(i in 1:dim(data)[[1]])
{
    res_mat[which(dimnames(res_mat)[[1]] == data[i,1]), which(dimnames(res_mat)[[2]] == data[i,2])] = data[i,3]
}

res_mat = t(res_mat)
res_mat = data.frame(res_mat)

+ Recent posts