[R] [ifelse] how to maintain a value from original matrix without probs?
Greg.Snow at imail.org
Fri Oct 31 18:02:15 CET 2008
The ifelse function sometimes has unwanted side effects. Your problem can easily be done with simple subsetting. Try:
> pos <- neg <- A
> pos[ pos <= 0 ] <- NA
> neg[ neg >= 0 ] <- NA
# remove the ='s if you don't want strict positive/negative
Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Diogo André Alagador
> Sent: Friday, October 31, 2008 8:59 AM
> To: r-help at r-project.org
> Subject: [R] [ifelse] how to maintain a value from original matrix
> without probs?
> Dear all,
> I have a matrix with positive and negative values.
> >From this I would like to produce 2 matrices:
> 1st - retaining positives and putting NA in other positions
> 2nd - retaining negatives and putting NA in other positions
> and then apply rowMeans for both.
> I am trying to use the function ifelse in the exemplified form:
> but by putting A as a 2nd parameter it changes dimensions of the
> I wonder if I can do this, as it seems not to difficult.
> thanks in advance
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help