1

私は nxn 型のマトリックスを持っていn = 100ます。

mat <- matrix (1:10000, nrow=100)
rownames (mat) <- paste ("I", 1:100, sep = "")
colnames (mat)  <- paste ("I", 1:100, sep = "")

特定の行 (または列) を選択し、小さな nxn 行列を作成したいと考えています。

# for example rows selected:
c(1, 20, 33, 44, 64).

したがって、結果の行列は次のようにループします。

        I1   I20   I33   I44  I64
I1
I20
I33
I44
I64

そうする方法はありますか?

4

1 に答える 1

5

それらを直接選択するだけです[row,col]

indices <- c(1, 20, 33, 44, 64)

mat[indices,indices]

> mat[indices,indices]
    I1  I20  I33  I44  I64
I1   1 1901 3201 4301 6301
I20 20 1920 3220 4320 6320
I33 33 1933 3233 4333 6333
I44 44 1944 3244 4344 6344
I64 64 1964 3264 4364 6364
于 2012-07-23T19:21:19.040 に答える