Skip to content

column names in matrix vs. data frame in R 1.8

3 messages · White.Denis@epamail.epa.gov, Brian Ripley, Peter Dalgaard

#
...
dimnames
names
consult
the
After thinking about this, I guess I wonder why names<- shouldn't have
the argument 'check.names' and/or check the class of its main argument.
Why offer protection in one situation and not another?
#
On Tue, 17 Feb 2004 White.Denis at epamail.epa.gov wrote:

            
I don't think you got the point.  names<- applies to a generic vector aka 
list, and the protection applies when generating data frames, not lists.
It really is a feature of data frames, not of lists and not of matrices.

More pedantically,
function (x, value) 
UseMethod("names<-")
<environment: namespace:base>

so there is no possibility of an extra argument for names<-, even if a 
data-frame method were added.
#
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
However, nothing is keeping you/us from defining a function fix.names
(say) so that you could do 

  names(dataframe) <- fix.names(nm)

(I have a sense of deja vu about this: Some other instance, where
adding arguments to an assignment function was actually possible, but
on closer thought, the wrong thing to do.)