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

Godmar Back godmar at gmail.com
Tue Jul 7 19:22:01 CEST 2009


On Tue, Jul 7, 2009 at 12:20 PM, David Winsemius<dwinsemius at comcast.net> wrote:
> 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
>

I thought along these lines, too, but:

> AA
     [,1]                [,2]                    [,3]
[1,] "overallimpression" "yourinitialimpression" "managementprocess_as_ord"
[2,] 0.7440637           0.7270246               0.5550202
     [,4]
[1,] "userinterfacechangedisplayorder:It was very easy to use with
either option"
[2,] -0.4476622

[ remainder deleted ]

> apply(AA, c(2,1), cat, "\n")
Error in cat(list(...), file, sep, fill, labels, append) :
  argument 1 (type 'list') cannot be handled by 'cat'

This may give more information about what AA is:

> attributes(AA)
$dim
[1]  2 13

> is.matrix(AA)
[1] TRUE

 - Godmar




More information about the R-help mailing list