I have two queries about the behaviour of drop() and apply() regarding the 
dimnames and names(dimnames) of the answer. I would appreciate any 
comments on this behaviour. I will submit any of this as a bug report if I 
am encouraged to do so.

The first query, concerning drop(), seems to me to be a bug in ?drop, and 
possibly also in the function.

?drop:
[...] Any accompanying 'dimnames' attribute is adjusted and returned with 
'x'.

> x <- array(dim=c(3,2,1), dimnames=list(A=NULL, B=NULL, C=NULL))

> attributes(drop(x))
$dim
[1] 3 2

> attributes(x[,,])
$dim
[1] 3 2

I expected a dimnames attribute equivalent to list(A=NULL, B=NULL). I 
think ?drop is misleading. Is the behaviour intended?

###########################################

I am less confident that the second query, concerning apply(), is a bug in 
anything. But I would appreciate an explanation of the behaviour.

> x <- array(dim=c(3,2), dimnames=list(A=1:3, B=1:2))

> apply(x, 1, function(row) row)
    A
      1  2  3
   1 NA NA NA
   2 NA NA NA

> attributes(apply(x, 1, function(row) row))
$dim
[1] 2 3

$dimnames
$dimnames[[1]]
[1] "1" "2"

$dimnames$A
[1] "1" "2" "3"

What has happened to the name of the first element of the list of dimnames 
of the answer? It seems arguable that if the rows of the answer are 
allowed to keep their names, then the name of that dimension should also 
be preserved. Should the behaviour be better documented in ?apply (which 
only discusses the effect on the dim attribute AFAICS).


Thanks for any comments. Please let me know if I should submit any bug 
reports concerning any of the above.

Dan

> version
          _
platform i386-pc-linux-gnu
arch     i386
os       linux-gnu
system   i386, linux-gnu
status
major    2
minor    2.0
year     2005
month    10
day      06
svn rev  35749
language R

Debian linux
[EMAIL PROTECTED]:~$ uname -a
Linux dd.princeton.edu 2.6.6 #1 SMP Fri Jul 16 13:23:04 EDT 2004 i686 
GNU/Linux

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to