我有一個向量x
。我想創建一個對元素的矩陣,它們的差值小於或等於1e-2
。我如何在R中做到這一點?R中的矩陣中的向量元素的差異
x = c(0.0001560653, 0.0001685597, 0.0002793819, 0.0006336307, 0.0455676525,
0.3184740837, 0.3195122279, 0.3195122606)
i = which(diff(x) <= 1e-2)
我期望的矩陣如下:
> M
[,1] [,2]
[1,] 0.0001560653 0.0001685597
[2,] 0.0001685597 0.0002793819
[3,] 0.0002793819 0.0006336307
[4,] 0.3184740837 0.3195122279
[5,] 0.3195122279 0.3195122606
+1爲簡潔和簡單 – mnel