[R] Printing with cat in a procedure

Steven Yen @tyen @ending from ntu@edu@tw
Sat Dec 22 16:13:47 CET 2018


Thank you all - print works wonders.

On 12/22/2018 10:36 PM, Eric Berger wrote:
> Hi Steven,
> Here's one way, using print
>
> try5<-function(A,B){
>   C<-A+B
>   #cat("\nA =",A,"\nC = ",C)
>   cat("\nA = ")
>   print(A)
>   cat("\nC = ")
>   print(C)
>   structure(list(A=A,B=B,C=C))
> }
>
> HTH,
> Eric
>
>
> On Sat, Dec 22, 2018 at 4:32 PM Steven Yen <styen using ntu.edu.tw 
> <mailto:styen using ntu.edu.tw>> wrote:
>
>     How do I print a matrix running a procedure? In the code below, I
>     print
>     with the cat command and get a vector (from A and C).
>
>     A<-matrix(rpois(16,lambda=5),nrow=4,byrow=T)
>     B<-diag(4)
>
>     try5<-function(A,B){
>       C<-A+B
>       cat("\nA =",A,"\nC = ",C)
>     structure(list(A=A,B=B,C=C))
>     }
>
>     v<-try5(A,B)
>     v$C
>
>     -- 
>     styen using ntu.edu.tw <mailto:styen using ntu.edu.tw> (S.T. Yen)
>
>
>             [[alternative HTML version deleted]]
>
>     ______________________________________________
>     R-help using r-project.org <mailto:R-help using r-project.org> mailing list --
>     To UNSUBSCRIBE and more, see
>     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.
>

-- 
styen using ntu.edu.tw (S.T. Yen)


	[[alternative HTML version deleted]]



More information about the R-help mailing list