On Thu, 8 Nov 2012, Hélio Guilherme wrote:
> Testing the examples added by Henrique to help of colnames and
> rownames functions, I get different outputs for the M matrix:
> ? matrix M = {1,2;2,1;4,1}
> matrix M = {1,2;2,1;4,1}
> Matriz M gerada
> ? rownames(M, "Row1 Row2 Row3")
> rownames(M, "Row1 Row2 Row3")
> ? print M
> print M
> M (3 x 2)
>
> Row1 1 2
> Row2 2 1
> Row3 4 1
>
> ? colnames(M, "Col1 Col2")
> colnames(M, "Col1 Col2")
> ? print M
> print M
> M (3 x 2)
>
> Col1 Col2
> Row1 1,0000 2,0000
> Row2 2,0000 1,0000
> Row3 4,0000 1,0000
>
> This is not a big problem but maybe we should have some control on the
> matrix elements numeric types (or at least consistency ;)). See ahead
> that is the colnames setting the numbers to float.
I'll take a look at the code on that. As for the points
regarding printf below, I think you're not fully understanding
how the "%f" and "%g" formats are supposed to work. Some
details follow.
> In the following experimentation with printf, there are missing
> separators within the matrix elements (output is using decimal commas
> since is the PT version):
>
> ? matrix M = {1,2;2,1;4,1}
> matrix M = {1,2;2,1;4,1}
> Matriz M gerada
> ? printf "%d", M
> 12
> 21
> 41
> ? printf "%0.3g", M
> 12
> 21
> 41
> ? printf "%0.3f", M
> 1,0002,000
> 2,0001,000
> 4,0001,000
When you use printf for matrices, you have to take charge of
the column width, using the width specifier as well as the
precision specifier. (In fact, above you're specifying a width
of 0.) A suitable format for this matrix would be "%6.3f" (or
increase the width for greater separation of the columns).
> Needs a fix:
> ? printf "%1.4g", N
> 1,0012,002
> 2,0021,001
> 4,0041,001
> ?
> Note that did not consider the requested 4 decimals.
With the format "%1.4g" you are requesting that the numbers be
printed with precision 4 -- and with 'g' that means 4
significant figures, not 4 decimal places -- but with width of
only 1. You should use something like "%6.4g" (with a width of
at least 6).
To be explicit, with both %f and %g, if you give a width
specification that is narrower than the width of the number as
printed according to the stated precision, it cannot be
honored, but the effect is that there is no "padding" around
the number -- so matrix columns will run into each other. (In
addition, if you give no width specification, as in "%.3f",
the numbers are again printed without any padding.)
Allin Cottrell