쉽게 3 마진 행렬을 병합하여 값의 열을 얻을 수 있습니다 ...
theta0 theta1 Yes No
Low Low 0.8377206 0.1622794
Low Med .. ..
Low High .. ..
Med Low .. ..
Med Med .. ..
Med High .. ..
High Low .. ..
High Med .. ..
High High .. ..
감사 : 내가 좋아하는 뭔가를 찾고 있어요 당신이 필요한 무엇
z1 <- apply(priCPT.i6, 3L, c)
## we can also simply use `matrix`; but remember to set `dimnames`
## otherwise we lose dimnames
## z1 <- matrix(priCPT.i6, ncol = 2L,
## dimnames = list(NULL, dimnames(priCPT.i6)[[3]]))
나머지는 "희미한"열을 추가하는 것입니다 :
z2 <- expand.grid(dimnames(priCPT.i6)[1:2])
이제 데이터 프레임에 병합 할 수 있습니다 reshape2을 것이 사용
data.frame(z2, z1)
재현 예
x <- array(1:18, dim = c(3L, 3L, 2L), dimnames = list(
c("Low", "Medium", "High"), c("Low", "Medium", "High"), c("Yes", "No")))
#, , Yes
#
# Low Medium High
#Low 1 4 7
#Medium 2 5 8
#High 3 6 9
#
#, , No
#
# Low Medium High
#Low 10 13 16
#Medium 11 14 17
#High 12 15 18
z1 <- apply(x, 3L, c)
## z1 <- matrix(x, ncol = 2L, dimnames = list(NULL, dimnames(x)[[3]]))
z2 <- expand.grid(dimnames(x)[1:2])
data.frame(z2, z1)
# Var1 Var2 Yes No
#1 Low Low 1 10
#2 Medium Low 2 11
#3 High Low 3 12
#4 Low Medium 4 13
#5 Medium Medium 5 14
#6 High Medium 6 15
#7 Low High 7 16
#8 Medium High 8 17
#9 High High 9 18
tidyr :: s pread (as.data.frame.table (priCPT.i6), Var3, Freq)' – alistaire