[R] ifelse, evaluating to given number

Peter Wilkinson pwilkinson at videotron.ca
Mon Jul 19 01:35:22 CEST 2004


yes,

so the short of it is ifelse uses whatever I use to represent the existing 
value in the 'test' expression.

I was thinking there was a reserved word for that like the $_ in perl 
...  but that works fine for me.


Peter


At 07:23 PM 7/18/2004, Adaikalavan Ramasamy wrote:
>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 at 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
> >




More information about the R-help mailing list