hadley/plyr — Issue #71: dapply(): .drop_o = FALSE results in additional nameless dimension
Author: alyst
Created: 2011-11-23 12:41:40+00:00
State: open

I want to convert a dataframe like this
```R
df1 <- data.frame( a = rep( 1:3, 6 ), b = rep( 1:3, each = 6 ), c = rnorm(9) )
```
into a matrix by doing
```R
daply( df1, .(a, b), function(x) mean(x$c) )
```
It works well, until my input data is degenerated, i.e. 'a' or 'b' columns or both contain only single value:
```R
df2 <- data.frame( a = 1:5, b = rep(1,5), c = rnorm(5) )
```
then daply() would simplify the result by removing the degenerated dimension and the result is no longer a matrix.
I thought that a workaround would be to use .drop_o = FALSE, but then the result is not a matrix, as expected, but a 3-dimensional vector, with one additional nameless dimension:
```R
str(daply( df2, .(a, b), function(x) as.numeric( mean(x$c) ), .drop_o = FALSE ))
```
gives
```
num [1:5, 1, 1] 0.2072 1.5926 -0.3159 -0.0117 -0.5506
- attr(*, "dimnames")=List of 3
..$ a: chr [1:5] "1" "2" "3" "4" ...
..$ b: chr "1"
..$ : chr "1
```

Is it a correct and expected behaviour?