[datatable-help] Syntax: ag["M",age]$age ?

Matthew Dowle mdowle at mdowle.plus.com
Sat Jan 21 02:43:43 CET 2012


Hi Steve,

Adding 'drop' does sound better. The original gripe was its default, not
drop itself I suppose. It might be handy when j isn't a single name,
too; e.g., 

> DT
     a v
[1,] A 1
[2,] A 2
[3,] B 3
[4,] B 4
[5,] B 5
> setkey(DT,a)
> DT[c("A","B"),sum(v)]$V1         # current
[1]  3 12
> DT[c("A","B"),sum(v),drop=TRUE]  # future
[1]  3 12

When j doesn't return a vector and drop=TRUE was supplied then it should
warn?; e.g.,

DT[c("A","B"),list(sum(v),min(v)),drop=TRUE]   # warning, ignoring drop

Matthew



On Fri, 2012-01-20 at 10:46 -0500, Steve Lianoglou wrote:
> Hi,
> 
> On Fri, Jan 20, 2012 at 7:19 AM, Matthew Dowle <mdowle at mdowle.plus.com> wrote:
> > Good question. I was thinking of changing it - in the special case that j
> > is a single name, it would return a vector. If the grouping columns were
> > needed just wrap the name with list(). We have a similar rule for i when
> > that's a single name.  The reason the grouping columns are always returned
> > was for consistency when there are multiple groups in i you probably want
> > to know which refer to which and we don't want a different type to be
> > returned depending on data passed to i.
> > It would be a non-backwards compatible change but we could return the old
> > bahaviour via an global option.
> > I get frustrated by it too, and it would be more efficient in those cases
> > as well.
> 
> Instead of special casing syntax like you suggest, doesn't this ave a
> natural "fit" with w/ the "idiomatic R" `drop=TRUE/FALSE` business?
> 
> I know it's not currently supported in data.table, but you could
> imagine always defaulting to FALSE, then in the single column case,
> you could do:
> 
>  ag["M",age, drop=TRUE]
> 
> or some such.
> 
> -steve
> 




More information about the datatable-help mailing list