[datatable-help] Skipping some Vi names

Matthew Dowle mdowle at mdowle.plus.com
Fri Jul 15 10:03:38 CEST 2011


Hi,

Yes, no quotes please. Also interested how you arrived at using quotes;
anything misleading in documentation please shout.

I've called it a bug though, fixed it, and added a test, so it can't
trip up users again. It was deparsing and reparsing j, which it didn't
need to do.

So in future this will happen :

> DT[,list("sum(a),sum(b)")]
                V1
[1,] sum(a),sum(b)

or, if DT contained 3 groups, this :

> DT[,list("sum(a),sum(b)"),by=a]
     a            V1
[1,] 1 sum(a),sum(b)
[2,] 2 sum(a),sum(b)
[3,] 3 sum(a),sum(b)
> 

Matthew


On Thu, 2011-07-14 at 18:14 -0400, Steve Lianoglou wrote:
> Hi Joseph,
> 
> On Thu, Jul 14, 2011 at 4:43 PM, Joseph Voelkel <jgvcqa at rit.edu> wrote:
> > Continuing with the example below, here is another problem: names() returns
> > NA’s for all Vi names except V1.
> >
> >> (dt2<-dt[,list("sum(A1),sum(A2),sum(A3)"),by="x,y"])
> >
> >      x y V1 V4 V5
> > [1,] 1 1  1  7 13
> > [2,] 1 2  4 10 16
> > [3,] 2 1  2  8 14
> > [4,] 2 3  5 11 17
> > [5,] 3 2  3  9 15
> > [6,] 3 3  6 12 18
> >
> >> names(dt2)
> >
> > [1] "x"  "y"  "V1" NA   NA
> 
> I'm curious why you put your expression in quotes? Did you see that in
> the manual somewhere?
> 
> Not doing that fixes your problems:
> 
> R> (dt2<-dt[,list(sum(A1),sum(A2),sum(A3)),by="x,y"])
>      x y V1 V2 V3
> [1,] 1 1  1  7 13
> [2,] 1 2  4 10 16
> [3,] 2 1  2  8 14
> [4,] 2 3  5 11 17
> [5,] 3 2  3  9 15
> [6,] 3 3  6 12 18
> 
> and
> 
> R> names(dt2)
> [1] "x"  "y"  "V1" "V2" "V3"
> 
> All columns are named, and there are no "gaps" in the colnames ...
> 
> I guess Matthew can comment on why this happens, but just use normal
> expressions/blocks for your `j` expression in the meantime :-)
> 
> If it's because you have a lot of column names, note that you can also do:
> 
> R> dt[,lapply(.SD, sum), by="x,y"]
> dt[,lapply(.SD, sum), by="x,y"]
>      x y A1 A2 A3
> [1,] 1 1  1  7 13
> [2,] 1 2  4 10 16
> [3,] 2 1  2  8 14
> [4,] 2 3  5 11 17
> [5,] 3 2  3  9 15
> [6,] 3 3  6 12 18
> 
> Note also that the column names are different here, too.
> 
> HTH,
> -steve
> 




More information about the datatable-help mailing list