Printing matrix/table in a procedure

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Printing matrix/table in a procedure

Steven Yen
Dear All,

I would like to get a matrix (table) printed in a procedure, as
attempted below. Please help. Thanks.

test<-function(x){
   table<-matrix(x,nrow=4)
   cat("\nTable:\n",table)
invisible(list(table=table))
}

x<-1:20
test(x)

--
[hidden email] (S.T. Yen)


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Printing matrix/table in a procedure

Rui Barradas
Hello,

What's wrong with

test <- function(x){
   table <- matrix(x, nrow = 4)
   cat("\nTable:\n")
   print(table)
   invisible(list(table = table))
}


Hope this helps,

Rui Barradas

Às 10:33 de 15/05/19, Steven Yen escreveu:

> Dear All,
>
> I would like to get a matrix (table) printed in a procedure, as
> attempted below. Please help. Thanks.
>
> test<-function(x){
>     table<-matrix(x,nrow=4)
>     cat("\nTable:\n",table)
> invisible(list(table=table))
> }
>
> x<-1:20
> test(x)
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Printing matrix/table in a procedure

Steven Yen
Great! Thanks.

On 5/15/2019 7:00 PM, Rui Barradas wrote:

> Hello,
>
> What's wrong with
>
> test <- function(x){
>   table <- matrix(x, nrow = 4)
>   cat("\nTable:\n")
>   print(table)
>   invisible(list(table = table))
> }
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 10:33 de 15/05/19, Steven Yen escreveu:
>> Dear All,
>>
>> I would like to get a matrix (table) printed in a procedure, as
>> attempted below. Please help. Thanks.
>>
>> test<-function(x){
>>     table<-matrix(x,nrow=4)
>>     cat("\nTable:\n",table)
>> invisible(list(table=table))
>> }
>>
>> x<-1:20
>> test(x)
>>
>

--
[hidden email] (S.T. Yen)


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.