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 Intermountain Healthcare [EMAIL PROTECTED] 801.408.8111 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of Diogo André Alagador > Sent: Friday, October 31, 2008 8:59 AM > To: r-help@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: > ifelse(A>0,A,NA) > but by putting A as a 2nd parameter it changes dimensions of the > original > object. > > I wonder if I can do this, as it seems not to difficult. > > thanks in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.