[Rd] Re: tail(<matrix>) column numbers

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri 09 Jul 2004 - 18:35:42 EST

>>>>> "PatBurns" == Patrick Burns <pburns@pburns.seanet.com>
>>>>> on Tue, 27 Jan 2004 14:20:30 +0000 writes:

[more than half a year ago]

    PatBurns> Duncan Murdoch wrote:

   .............

    DM> One other one I'll look at:
    DM> 
    DM> If a matrix doesn't have row names, I might add names
    DM> like '[nn,]' to it, so I get results like

      R> x <- matrix(1:100,ncol=2)
      R> tail(x)
   Rout>       [,1] [,2]
   Rout> [45,]   45   95
   Rout> [46,]   46   96
   Rout> [47,]   47   97
   Rout> [48,]   48   98
   Rout> [49,]   49   99

   Rout> [50,] 50 100
   Rout>
    DM> instead of the current
      R> tail(x)
   Rout>      [,1] [,2]
   Rout> [1,]   45   95
   Rout> [2,]   46   96
   Rout> [3,]   47   97
   Rout> [4,]   48   98
   Rout> [5,]   49   99
   Rout> [6,]   50  100

    DM> I just want to be careful that this doesn't mess up
    DM> something else.

    DM>
    DM> Duncan Murdoch
    PatBurns> I think this could be being too "helpful".  Using
    PatBurns> tail on a matrix may often be done in a program so
    PatBurns> I think leaving things as they come is the best
    PatBurns> policy.

I tend to disagree, and would like to have us think about it again:

  1. Duncan's proposal was to only add row names *when* there are none.
  2. Pat is write that tail() for matrices maybe used not only interactively and help(tail)'s "Value:" section encourages this to some extent.

    However, how can adding column names to such a matrix-tail be harmful?

    Well, only in the case where the tail is quite large, the     added dimnames add unneeded memory and other overhead when     dealing with that matrix.

 But I think, programmers/users caring about efficient code  wouldn't use tail(<matrix>) in their function code, would they?

In conclusion, I'd still argue for following Duncan's proposal, maybe adding a \note{.} to head.Rd stating that these functions were meant for interactive use, and for "programming", we'd rather recommend the direct (n-k+1):n indexing.



R-devel@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-devel Received on Fri Jul 09 18:39:50 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 08:59:07 EST