[R] Problem with cat() == A related question

jim holtman jholtman at gmail.com
Tue Sep 14 17:05:28 CEST 2010


Try the following:

 fn1 <- function(n = 5){
 mat <- matrix(rnorm(5*5), 5, 5)
  cat(print(mat))
 invisible(NULL)}

On Tue, Sep 14, 2010 at 9:59 AM, Peng, C <cpeng.usm at gmail.com> wrote:
>
> Code:
>
>> fn1 <- function(n = 5){
> +  mat <- matrix(rnorm(5*5), 5, 5)
> +  cat(print(mat))
> + }
>> fn1()
>           [,1]        [,2]       [,3]        [,4]       [,5]
> [1,] -0.7101952  0.78992424 -0.8310871  2.49560703 -0.9543827
> [2,] -0.1425682 -2.69186367 -0.5937949  0.03188572 -0.5512154
> [3,] -0.3041728  0.05099222 -2.0905322  0.19254519 -0.1208534
> [4,]  2.0812597  1.22048195  1.9347253 -1.25478253  1.2998755
> [5,]  0.9256113  0.02686392 -0.1059670 -2.62715239 -0.4826737
> -0.7101952 -0.1425682 -0.3041728 2.081260 0.9256113 0.7899242 -2.691864
> 0.05099222 1.220482 0.02686392 -0.8310871 -0.5937949 -2.090532 1.934725
> -0.1059670 2.495607 0.03188572 0.1925452 -1.254783 -2.627152 -0.9543827
> -0.5512154 -0.1208534 1.299876 -0.4826737>
>>
>
> Question: Is there any control arguments can be used such that fn1() ONLY
> prints out the matrix part?
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2539017.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list