On Aug 11, 2014, at 3:27 PM, Jinsong Zhao wrote:
> On 2014/8/11 14:50, William Dunlap wrote:
>> 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
>
On 2014/8/11 14:50, William Dunlap wrote:
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 Dunla
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, Au
(m>1)+1
On Mon, Aug 11, 2014 at 5:40 PM, Jinsong Zhao wrote:
> Hi there,
>
> I hope to replace a range of numeric in a matrix with a integer. For
> example, in the following matrix, I want to use 1 to replace the elements
> range from 0.0 to 1.0, and all larger than 1. with 2.
>
>> (m <- matrix(r
Hi there,
I hope to replace a range of numeric in a matrix with a integer. For
example, in the following matrix, I want to use 1 to replace the
elements range from 0.0 to 1.0, and all larger than 1. with 2.
> (m <- matrix(runif(16, 0, 2), nrow = 4))
[,1] [,2] [,3] [,4
5 matches
Mail list logo