[datatable-help] Skipping some Vi names
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri Jul 15 00:14:53 CEST 2011
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
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the datatable-help
mailing list