# 创建一个矩阵 m 并设置为位置 mij = (i+j)*10Create a matrix m and set to the positions mij = (i+j)*10

``````Matrix:
20  30  40  50  60

30  ...

40  ...

50  ...

60  ...
``````

## 3 个回复3

### #1楼 票数：1

``````> outer(1:5,1:5,"+")*10

[,1] [,2] [,3] [,4] [,5]
[1,]   20   30   40   50   60
[2,]   30   40   50   60   70
[3,]   40   50   60   70   80
[4,]   50   60   70   80   90
[5,]   60   70   80   90  100
``````

### #2楼 票数：0

``````i <- 4
j <- 5
(matrix(1:j, i, j, byrow = TRUE) + matrix(1:i, i, j)) * 10
[,1] [,2] [,3] [,4] [,5]
[1,]   20   30   40   50   60
[2,]   30   40   50   60   70
[3,]   40   50   60   70   80
[4,]   50   60   70   80   90
``````

### #3楼 票数：0 已采纳

@user2974951除了`outer`方法之外的另一个基本 R 解决方案

``````n <- 5
mat <-(t(replicate(n,seq(n)))+seq(n))*10
``````

``````> mat
[,1] [,2] [,3] [,4] [,5]
[1,]   20   30   40   50   60
[2,]   30   40   50   60   70
[3,]   40   50   60   70   80
[4,]   50   60   70   80   90
[5,]   60   70   80   90  100
``````

1回复

2回复

1回复

2回复

1回复

1回复

2回复

2回复