; , , . , K, . K[] <- , dataframe. LHS K, , , :
dfm <- expand.grid(x1=1:2,x2=1:2,y1=1:2,y2=1:2)
K[] <- with(dfm, x1*y2 - sin(x2*y1 ) )
:
data.frame x1, x2, y1, y2 , : K [cbind (index-vectors)] < - values construction:
mtx<- data.matrix( expand.grid(x1=1:2,x2=1:2,y1=1:2,y2=1:2) )
K[mtx] <- apply(mtx, 1, function(x) x["x1"]*x["y2"] - sin(x['x2']*x['y1']) )
#----------------
> K
, , 1, 1
[,1] [,2]
[1,] 0.158529 0.09070257
[2,] 1.158529 1.09070257
, , 2, 1
[,1] [,2]
[1,] 0.09070257 1.756802
[2,] 1.09070257 2.756802
, , 1, 2
[,1] [,2]
[1,] 1.158529 1.090703
[2,] 3.158529 3.090703
, , 2, 2
[,1] [,2]
[1,] 1.090703 2.756802
[2,] 3.090703 4.756802