Skip to content
Prev 343033 / 398513 Next

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

You can use
    m[m > 0 & m <= 1.0] <- 1
    m[m > 1 ] <- 2
or, if you have lots of intervals, something based on findInterval().  E.g.,
    m[] <- findInterval(m, c(-Inf, 0, 1, Inf)) - 1

(What do you want to do with non-positive numbers?)

Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Aug 11, 2014 at 2:40 PM, Jinsong Zhao <jszhao at yeah.net> wrote: