Skip to content
Prev 343035 / 398513 Next

efficient way to replace a range of numeric with a integer in a matrix

On Aug 11, 2014, at 3:27 PM, Jinsong Zhao wrote:

            
OR, if you have irregularly spaced intervals or particular values to match to the intervals,  you can use findInterval to define categories and select with "[":
[,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
 [1,] 16.85 16.52  8.47 12.28 11.03 11.61  8.16  4.78 17.56 16.96
 [2,]  7.18 21.43  1.09 13.52  8.19  6.08 10.93  9.55 11.29  7.62
 [3,] 11.82  3.06  9.14 15.18 13.79 17.88 12.91 13.12 10.44 13.25
 [4,] 13.16  8.61 16.07  6.96  6.37 13.21 17.00  5.23  9.40 16.96
 [5,] 12.02  9.33 19.48 12.52  3.16 10.45  6.36  7.29  4.03  4.45
 [6,]  9.47 13.18  7.85  1.41 12.16 11.38 16.51 12.90 13.06  5.70
 [7,] 17.56  8.58  8.71  6.08  5.94 13.40 11.68 13.84  8.91  4.34
 [8,]  9.53 -3.28  1.18  5.75 17.22 10.45 15.19 12.32  9.09  2.70
 [9,] 20.09 -2.20 12.30 -2.07  7.84 -4.97 14.60  5.57 14.67 10.40
[10,]  9.69 16.60  6.80 10.18 13.28 11.42 13.60  4.50 14.11 13.27
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   16   16    4    8    8    8    4    2   16    16
 [2,]    4   32    1    8    4    4    8    4    8     4
 [3,]    8    2    4   16    8   16    8    8    8     8
 [4,]    8    4   16    4    4    8   16    4    4    16
 [5,]    8    4   32    8    2    8    4    4    2     2
 [6,]    4    8    4    1    8    8   16    8    8     4
 [7,]   16    4    4    4    4    8    8    8    4     2
 [8,]    4    1    1    4   16    8   16    8    4     2
 [9,]   32    1    8    1    4    1    8    4    8     8
[10,]    4   16    4    8    8    8    8    2    8     8