[R] column names in matrix vs. data frame in R 1.8

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Feb 17 21:59:16 CET 2004

Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

> > 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?
> 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,
> > get("names<-")
> 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.

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.)

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

More information about the R-help mailing list