AARRGGHH! Sometimes it's the simple things that are particularly frustrating, especially late at night.... Can anyone suggest a simple means for replacing all of the zero values in a matrix with NANs? I ended up writing an awk script to massage the input file, which works, of course, but is rather an inelegant blunt instrument. I'd prefer an R operation. I'm certain that I'm missing something obvious here.... --Mike ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Michael A. Camann mac24 at axe.humboldt.edu Assistant Professor of Zoology Voice: 707-826-3676 Dept. of Biological Sciences Fax: 707-826-3201 Humboldt State University Arcata, CA 95521-8299 http://www.humboldt.edu/~mac24/camann.html ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, Aug 02, 1999 at 03:14:43PM -0700, Michael Camann wrote:> AARRGGHH! Sometimes it's the simple things that are particularly frustrating, > especially late at night.... > > Can anyone suggest a simple means for replacing all of the zero values in a > matrix with NANs? I ended up writing an awk script to massage the input file, > which works, of course, but is rather an inelegant blunt instrument. I'd > prefer an R operation. I'm certain that I'm missing something obvious here.... > > --Mike >I might be missing something, but why not: x[x==0] <- NaN A small test example:> x<-matrix(0,nr=3,nc=3) > x[,1] [,2] [,3] [1,] 0 0 0 [2,] 0 0 0 [3,] 0 0 0> x[x==0] <- NaN > x[,1] [,2] [,3] [1,] NaN NaN NaN [2,] NaN NaN NaN [3,] NaN NaN NaN> is.nan(x)[,1] [,2] [,3] [1,] TRUE TRUE TRUE [2,] TRUE TRUE TRUE [3,] TRUE TRUE TRUE -- +-------------------------------------------------------------------------+ | Robert Gentleman voice: (617) 632-5045 | | Senior Lecturer fax: (617) 632-2444 | | University of Auckland email1: rgentlem at jimmy.harvard.edu | | on leave at: | | Dana-Farber Cancer Institute email2: rgentlem at stat.auckland.ac.nz | +-------------------------------------------------------------------------+ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
X-Authentication-Warning: stat.math.ethz.ch: majordom set sender to owner-r-help at stat.math.ethz.ch using -f Date: Mon, 2 Aug 1999 15:14:43 -0700 From: Michael Camann <camann at babylon.cnrs.humboldt.edu> X-Status: N X-Mailer: Applixware 4.3 (807.141.90) Sender: owner-r-help at stat.math.ethz.ch Precedence: bulk AARRGGHH! Sometimes it's the simple things that are particularly frustrating, especially late at night.... Can anyone suggest a simple means for replacing all of the zero values in a matrix with NANs? I ended up writing an awk script to massage the input file, which works, of course, but is rather an inelegant blunt instrument. I'd prefer an R operation. I'm certain that I'm missing something obvious here.... --Mike ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Michael A. Camann mac24 at axe.humboldt.edu Assistant Professor of Zoology Voice: 707-826-3676 Dept. of Biological Sciences Fax: 707-826-3201 Humboldt State University Arcata, CA 95521-8299 http://www.humboldt.edu/~mac24/camann.html ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ z[z==0]<-NA -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._