>>>>> William Revelle <li...@revelle.net> >>>>> on Tue, 14 Sep 2010 14:52:32 -0500 writes:
> At 3:45 PM -0400 9/14/10, jim holtman wrote: >> The problem is the 'cat' enclosing the 'print'; just get rid of the >> 'cat' -- that is what is causing the extra output >> >> On Tue, Sep 14, 2010 at 3:34 PM, Peng, C <cpeng....@gmail.com> wrote: >>> >>> It is still visible even it is set invisible(NULL): >>> >>>> fn1 <- function(n = 5){ >>> + mat <- matrix(rnorm(5*5), 5, 5) >>> + cat(print(mat)) >>> + invisible(NULL)} >>>> fn1() >>> [,1] [,2] [,3] [,4] [,5] >>> [1,] -1.22767085 -1.41468587 -2.0156231 0.29732942 0.5755600 >>> [2,] -0.16775996 -0.03780596 -0.9461079 0.91289175 0.1254273 >>> [3,] 0.09696032 -0.75522210 -0.7494442 -0.21341669 1.7088194 >>> [4,] 0.13535505 -1.09011005 -0.6074198 0.05342614 -1.1996344 >>> [5,] 0.66474083 -2.62206248 0.1329972 0.06132865 0.5124778 >>> -1.227671 -0.1677600 0.09696032 0.1353550 0.6647408 -1.414686 -0.03780596 >>> -0.7552221 -1.09011 -2.622062 -2.015623 -0.9461079 -0.7494442 -0.6074198 >>> 0.1329972 0.2973294 0.9128917 -0.2134167 0.05342614 0.06132865 0.57556 >>> 0.1254273 1.708819 -1.199634 0.5124778> >>>> >>> -- >>> View this message in context: >>> http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2539551.html >>> Sent from the R help mailing list archive at Nabble.com. >>> > I think that what Peng was trying to do was print it without the > column and row names >> mat <- matrix(1:25,5,5) >> colnames(mat) <- rownames(mat) <- rep("",5) >> print(mat) > 1 6 11 16 21 > 2 7 12 17 22 > 3 8 13 18 23 > 4 9 14 19 24 > 5 10 15 20 25 Yes. A (slightly more general and efficient) version is > sfsmisc::empty.dimnames( matrix(1:40, 5,8) ) 1 6 11 16 21 26 31 36 2 7 12 17 22 27 32 37 3 8 13 18 23 28 33 38 4 9 14 19 24 29 34 39 5 10 15 20 25 30 35 40 > --- where the empty.dimnames() function is just one small reason to get the "sfsmisc" package ;-) Martin Maechler, ETH Zurich ______________________________________________ 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.