Re: [R] ifelse, evaluating to given number

From: Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk>
Date: Mon 19 Jul 2004 - 09:23:45 EST

Is this what you want ?

> m <- matrix( 1:12, nc=3 )
> m

     [,1] [,2] [,3]

[1,]    1    5    9
[2,]    2    6   10
[3,]    3    7   11
[4,]    4    8   12


> ifelse( m < 6.5, 999, m )
[,1] [,2] [,3] [1,] 999 999 9 [2,] 999 999 10

[3,] 999 7 11
[4,] 999 8 12

On Mon, 2004-07-19 at 00:08, Peter Wilkinson wrote:
> I would like to take advantage of the vectorized 'ifelse' command. Given a
> filter number of 'filter', if the nm'th value in a n x m matrix I would
> like to perform the following.
>
> newMatrix <- ifelse(myMat <=filter, filter+1, "existing nm'th value").
>
> What do I use to express the "existing nm'th value" in this expression if I
> want to test an nm th value is less than 'filter', if false use the
> existing nm'th value.
>
> This does not seem to be documented in the help().
>
> Peter W.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 19 09:32:12 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:36:43 EST