s-news
[Top] [All Lists]

Annotated printing of arrays with named dimnames

To: S news submissions <s-news@wubios.wustl.edu>
Subject: Annotated printing of arrays with named dimnames
From: "Charles E. (Ted) Wright" <cew@aris.ss.uci.edu>
Date: Mon, 19 Feb 2001 10:57:44 -0800 (PST)
One aspect of S that bothers me (this applies to Version 5 for Unix, as well
as older versions that I still sometimes run) is that when printing matrices
or arrays there is no easy way to have labels for the dimensions printed
along with the labels for the levels of each dimension.  Because it is
possible to name the elements of the dimnames list, the data structures
necessary to support this type of labeling exist.  So, for example, when
printing the following simple matrix (whose structure below has been dumped
with dput())

matrix(c(1, 2, 3, 4) , nrow = 2, ncol = 2
  dimnames = list("Fact1" = c("L1", "L2") , "Fact2" = c("L1", "L2") ) )

I would prefer output that looks like

           Fact2
           L1 L2
Fact1   L1  1  3
        L2  2  4

rather than the current default which is

   L1 L2
L1  1  3
L2  2  4

This approach is, I believe, upward compatible because most of the time the
dimnames components are not named and, in this case, the current default
output would presumably be produced.

Has anyone already come up with a way to do this?

Ted Wright



<Prev in Thread] Current Thread [Next in Thread>
  • Annotated printing of arrays with named dimnames, Charles E. (Ted) Wright <=