[Rd] Drop single-dimensional array

Arni Magnusson arnima at hafro.is
Wed Sep 8 20:54:41 CEST 2010

Hi Simon, thank you for the concise reply.

Do you mean the reported behavior of drop() is not a bug?

It looks like a borderline bug to me (see below), but I'm not the judge of 
that. If this is the intended behavior and serves an actual purpose, then 
that could be explicitly documented in a \note{} on the help page.

Such a note would slightly reduce the surprise of users running into this 

This is related to the oddity that one-dimensional arrays are:

   array(month.abb, dim=c(1,1,12))  # array
   array(month.abb, dim=c(1,12))    # matrix
   array(month.abb, dim=12)         # array

Firstly, one would expect the pattern to be array-matrix-vector. Secondly, 
it's easy to drop() the three-dimensional and two-dimensional objects, but 
drop() does nothing to the one-dimensional array. Instead, it takes an 
unintuitive combination of methods to convert a single-dimensional to a 
vector, while retaining its names. Or I may well be missing something 

Best regards,


On Wed, 8 Sep 2010, Simon Urbanek wrote:

> wrong address - did you mean R-devel?
> Simon
> On Sep 6, 2010, at 8:35 AM, Arni Magnusson wrote:
>> Bug or not, I was surprised by this behavior:
>>  x <- tapply(chickwts$weight, chickwts$feed, median)
>>  x  # array ... I'd like to convert to vector with named elements
>>  drop(x)             # what, still an array?
>>  drop(as.matrix(x))  # this works
>>  drop(t(x))          # this works
>> I was expecting drop(x) to return a vector, and I suspect many R users 
>> would too. The title in help(drop), "Drop Redundant Extent 
>> Information", suggests that such a simple array would be converted to a 
>> vector.
>> Reading through the help page, I note that this is perhaps not a clear 
>> bug, but somewhat unclear behavior.
>> The most compact way to break the vector out of its eggshell seems to 
>> be
>>  t(x)[,]
>> but drop(x) would be much easier to read and write. There's nothing 
>> particularly matrix about x, so it's not obvious that the conversion 
>> should involve as.matrix(x).
>> Thanks,
>> Arni

More information about the R-devel mailing list