f******9 发帖数: 267 | 1 How to find the numbers which are more than 0.5 in a matrix (and with their
rownames and colnames)?
for example, in this matrix:
[,1] [,2] [,3] [,4] [,5]
[1,] 1.0000000000 0.0320075758 0.1183712121 0.0293040293 0.0083333333
[2,] 0.0320075758 1.0000000000 0.0571428571 0.1668650794 0.0004662005
[3,] 0.1183712121 0.0571428571 1.0000000000 0.0053418803 0.0028846154
[4,] 0.0293040293 0.1668650794 0.0053418803 1.0000000000 0.0426767677
[5,] 0.008333 | R*********r 发帖数: 225 | 2 which(X>0.5)
> X <- matrix(rnorm(25, 0,1),nrow=5)
> X
[,1] [,2] [,3] [,4] [,5]
[1,] 1.1050564 2.3754090 1.3176173 -1.5279143 1.1355724
[2,] 0.4067519 0.2387128 -1.1444963 -0.6691630 -0.8591197
[3,] 0.4040506 0.3869183 0.2218467 -0.3432441 0.9440614
[4,] -0.5409871 0.4164543 1.1699040 -0.2741125 0.5039738
[5,] -0.5846117 1.0009905 -1.9204391 1.0342027 0.1003464
In R, matrix's entries are indexed column by column.
thus
X[1,2] == X[6]
Not recommended but
【在 f******9 的大作中提到】 : How to find the numbers which are more than 0.5 in a matrix (and with their : rownames and colnames)? : for example, in this matrix: : [,1] [,2] [,3] [,4] [,5] : : [1,] 1.0000000000 0.0320075758 0.1183712121 0.0293040293 0.0083333333 : [2,] 0.0320075758 1.0000000000 0.0571428571 0.1668650794 0.0004662005 : [3,] 0.1183712121 0.0571428571 1.0000000000 0.0053418803 0.0028846154 : [4,] 0.0293040293 0.1668650794 0.0053418803 1.0000000000 0.0426767677 : [5,] 0.008333
| t**i 发帖数: 688 | 3 > X <- matrix(rnorm(25, 0,1),nrow=5)
> X
[,1] [,2] [,3] [,4] [,5]
[1,] 1.56280941 -1.9127071 -0.626082 -1.0988275 0.5192378
[2,] -0.96582879 1.8160815 -2.319349 0.4177512 -0.2148984
[3,] 0.05563102 0.1863339 1.254996 -0.2122877 -0.4268865
[4,] 0.97439281 -0.1713336 2.012629 -1.3479961 1.8149157
[5,] -1.17377646 1.0095202 1.553646 -1.9188167 -1.4827899
> Y = X>0.5
> Y
[,1] [,2] [,3] [,4] [,5]
[1,] TRUE FALSE FALSE FALSE TRUE
[2,] FALSE T | D******n 发帖数: 2836 | 4 cbind(which(X>0.5,arr.ind=T),X[X>0.5]) | f******9 发帖数: 267 | 5 很感谢!
【在 R*********r 的大作中提到】 : which(X>0.5) : > X <- matrix(rnorm(25, 0,1),nrow=5) : > X : [,1] [,2] [,3] [,4] [,5] : [1,] 1.1050564 2.3754090 1.3176173 -1.5279143 1.1355724 : [2,] 0.4067519 0.2387128 -1.1444963 -0.6691630 -0.8591197 : [3,] 0.4040506 0.3869183 0.2218467 -0.3432441 0.9440614 : [4,] -0.5409871 0.4164543 1.1699040 -0.2741125 0.5039738 : [5,] -0.5846117 1.0009905 -1.9204391 1.0342027 0.1003464 : In R, matrix's entries are indexed column by column.
| f******9 发帖数: 267 | 6 Thank tosi!
另外R中这个%是用来干啥的啊?
【在 t**i 的大作中提到】 : > X <- matrix(rnorm(25, 0,1),nrow=5) : > X : [,1] [,2] [,3] [,4] [,5] : [1,] 1.56280941 -1.9127071 -0.626082 -1.0988275 0.5192378 : [2,] -0.96582879 1.8160815 -2.319349 0.4177512 -0.2148984 : [3,] 0.05563102 0.1863339 1.254996 -0.2122877 -0.4268865 : [4,] 0.97439281 -0.1713336 2.012629 -1.3479961 1.8149157 : [5,] -1.17377646 1.0095202 1.553646 -1.9188167 -1.4827899 : > Y = X>0.5 : > Y
| f******9 发帖数: 267 | 7 非常感谢!谢谢啦DaShagen
【在 D******n 的大作中提到】 : cbind(which(X>0.5,arr.ind=T),X[X>0.5])
|
|