Hello, If it does not *have* to be cat(), this would work:
fn1 <- function(n = 5){ mat <- matrix(rnorm(5*5), 5, 5) print(mat) return(n) } Cheers, Josh On Tue, Sep 14, 2010 at 4:00 AM, Christofer Bogaso <bogaso.christo...@gmail.com> wrote: > Dear all, I have a problem with the cat() function. Let say I have following: > > fn1 <- function(n = 5){ > mat <- matrix(rnorm(5*5), 5, 5) > cat(as.character(mat)) > return(n) > } > > However when I run above function I get this: >> fn1() > -0.601930631438248 -1.16950049447942 0.469257329394626 > -1.39766868242906 -1.02580943892082 1.4067931110327 -1.07245318857022 > -0.0205043699310245 0.234628727206755 2.20623115088835 > 0.689246510169205 0.390165590650482 1.16264636627546 -1.26460050014308 > -0.0618394808642369 1.55065748588694 -1.09179651631271 > 1.77868450520847 1.56281762714862 -0.0428547138289468 -1.5041448417776 > 0.221592557337622 -1.91535929883353 -0.712994991755814 > -0.440738636680476[1] 5 > > > How can I preserve the "matrix" format while printing? > > Thanks, > > ______________________________________________ > 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. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ ______________________________________________ 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.