7

(i、j)エントリがiとjの関数である行列(Rセンスではなく、通常のセンス)をどのように作成しますか?関係があると思いますapply()が、使い方がわからないようです。

Say if I have columns x1, x2, ... and rows y1,y2 where the x1 and y1 are R objects and I want to build a table/matrix where the entry is a function of xi and yj for each i and j.

Sorry if this has been answered elsewhere.

4

1 に答える 1

11

質問全体を理解できるかわかりません。最初の文の質問に答えます。

fun <- function(i,j) i*j

rows <- 1:5
cols <- 1:3

outer(rows,cols,FUN=fun)

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
[3,]    3    6    9
[4,]    4    8   12
[5,]    5   10   15
于 2012-09-26T07:12:58.577 に答える