R-bugs is not the place to ask questions, see the FAQ .... On Fri, 11 Aug 2006, [EMAIL PROTECTED] wrote:
[...] > A separate but related question (not a bug) has to do with the handling > of dimnames for 0-extent arrays. If an array starts out with non-NULL > dimnames and is subscripted down to have 0-extent, the corresponding > component is set to NULL, rather than character(0): and that dimension does not have any names, so this is appropriate. > dimnames(tmp[0,,drop=FALSE]) # first component is NULL > > Why is that? Note that this is different from how data frames are > handled: > > tmp.df <- data.frame(tmp) > dimnames(tmp.df[0,]) # first component is character(0) Data frames do not have 'dimnames', and what is reported by the accessor function is list(row.names(x), names(x)), both of which are required to be character vectors. Indeed, as the help file says For the \code{"data.frame"} method both dimnames must be non-null, and the rownames must contain no duplicates nor missing values. > The description in ?dimnames seems to allow character(0) components > of dimnames, > > "The dimnames of a matrix or array can be 'NULL' or a list of the > same length as 'dim(x)'. If a list, its components are either > 'NULL' or a character vector the length of the appropriate > dimension of 'x'." That is accurate. > yet the implementation seems to resist them: > > tmp2 <- tmp[0,,drop=FALSE] > dimnames(tmp2) <- list(character(0), LETTERS[1:3]) > dimnames(tmp2) # still NULL > > So my question is whether it would be reasonable to change 'dimnames' > and/or "dimnames<-" to use (or at least allow) character(0) rather than > NULL for array dimensions of 0 extent. Why would it be desirable to have two equivalent representations of the same thing (no names)? As you could easily have found out, the C code replaces a zero-length vector by NULL. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel