回答編集履歴
2
Update
test
CHANGED
@@ -1,14 +1,10 @@
|
|
1
|
-
以下は `expand.grid`
|
1
|
+
以下は `expand.grid` を使う方法です。
|
2
2
|
|
3
3
|
```r
|
4
4
|
|
5
5
|
r <- 4
|
6
6
|
|
7
|
-
array <- do.call(mapply,
|
8
|
-
|
9
|
-
c(function(j, i, k) i^k - j^k,
|
10
|
-
|
11
|
-
|
7
|
+
array <- do.call(function(j, i, k) i^k - j^k, expand.grid(j=1:r, i=1:r, k=1:(r-1)))
|
12
8
|
|
13
9
|
array <- unname(split(array, rep(1:(r-1), each=r*r)))
|
14
10
|
|
@@ -46,11 +42,7 @@
|
|
46
42
|
|
47
43
|
r <- 4
|
48
44
|
|
49
|
-
array <- do.call(mapply,
|
50
|
-
|
51
|
-
c(function(j, i, k) i^k - j^k,
|
52
|
-
|
53
|
-
|
45
|
+
array <- do.call(function(j, i, k) i^k - j^k, expand.grid(j=1:r, i=1:r, k=1:(r-1)))
|
54
46
|
|
55
47
|
mat <- matrix(array, ncol=r*r, byrow=T)
|
56
48
|
|
1
Update
test
CHANGED
@@ -37,3 +37,37 @@
|
|
37
37
|
[1] 0 -7 -26 -63 7 0 -19 -56 26 19 0 -37 63 56 37 0
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
リストではなく行列(matrix)にする場合は以下になります。
|
44
|
+
|
45
|
+
```r
|
46
|
+
|
47
|
+
r <- 4
|
48
|
+
|
49
|
+
array <- do.call(mapply,
|
50
|
+
|
51
|
+
c(function(j, i, k) i^k - j^k,
|
52
|
+
|
53
|
+
expand.grid(j=1:r, i=1:r, k=1:(r-1))))
|
54
|
+
|
55
|
+
mat <- matrix(array, ncol=r*r, byrow=T)
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
print(mat)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
#
|
64
|
+
|
65
|
+
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16]
|
66
|
+
|
67
|
+
[1,] 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0
|
68
|
+
|
69
|
+
[2,] 0 -3 -8 -15 3 0 -5 -12 8 5 0 -7 15 12 7 0
|
70
|
+
|
71
|
+
[3,] 0 -7 -26 -63 7 0 -19 -56 26 19 0 -37 63 56 37 0
|
72
|
+
|
73
|
+
```
|