[R] how to get R to print only one column per line when outputting a matrix?

David Winsemius dwinsemius at comcast.net
Tue Jul 7 18:20:02 CEST 2009


It looks like you are printing a matrix and that you want to print all  
rows of the first column before all rows of the second column. Apply  
should do it. Assume the matrix is named "AA"

apply(AA, c(2,1), cat, "\n")   # the \n is the line-feed character

-- 
DW


On Jul 7, 2009, at 10:06 AM, Godmar Back wrote:

> Hi,
>
> I'm trying to make it easier for my survey evaluators to read the
> results of my survey analysis. To that end, I'd like to suppress R's
> habit of filling every line up to width columns.  How do I do that?
>
> For instance, using 'print()', R outputs something like:

But you have not offered the code that produced this.

>
>     [,1]                     [,2]
> var2 "someshortname" "someothershortname"
> r    0.3341755                0.3275274
> N    136                      136
>     [,3]
> var2 "somereallyreallyreallyreallyreallylongname"
> r    0.323306
> N    136
>     [,4]
> var2 "someotherreallyreallyreallyreallyreallylongname"
> r    0.3121291
> N    101
> ----
>
> How can I get it to place every column on a new line to avoid
> confusing the reader?
>
> I read the help for print, print.default, format, cat, and
> options(width) and wasn't able to find an answer.
>
> Thanks!
>
> - Godmar
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list