Здесь простое и быстрое решение (без объединения):
t((matrix(df[,"shape_index"][as.vector(m)+1],nrow=11,ncol=7)))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 24.78 24.78 24.78 24.78 24.78 24.78 7.02 7.02 7.02 7.02 24.78
[2,] 24.78 24.78 14.70 14.70 24.78 24.78 7.02 7.02 24.78 24.78 24.78
[3,] 24.78 24.78 24.78 14.70 14.70 24.78 24.78 24.78 24.78 2.48 2.48
[4,] 24.78 24.78 14.70 24.78 14.70 24.78 6.36 6.36 24.78 2.48 2.48
[5,] 24.78 24.78 24.78 24.78 14.70 24.78 24.78 6.36 24.78 24.78 2.48
[6,] 24.78 11.68 24.78 24.78 24.78 24.78 6.36 6.36 24.78 24.78 24.78
[7,] 24.78 11.68 11.68 11.68 24.78 24.78 24.78 24.78 24.78 2.43 2.43
В этом коде я использую значения от m
в качестве позиции [+1 отрегулировано] в df$shape_index
Входные данные:
df<-data.frame(PatchID=c(0,1,2,3,4,5,6),
area=c(11592800,2556440,3562800,2945450,3892610,7678785680,1756784547),
shape_index=c(24.78,7.02,14.70,2.48,6.36,11.68,2.43))
m<-matrix(c(0,0,0,0,0,0,1,1,1,1,0,
0,0,2,2,0,0,1,1,0,0,0,
0,0,0,2,2,0,0,0,0,3,3,
0,0,2,0,2,0,4,4,0,3,3,
0,0,0,0,2,0,0,4,0,0,3,
0,5,0,0,0,0,4,4,0,0,0,
0,5,5,5,0,0,0,0,0,6,6),nrow=7,ncol=11)