as.data.table(lapply(DT, sum)) works and doesn't seem much less elegant?

(Well -- it would work if you were not trying to take the sum of a factor
;-))

t

On Mon, Jan 9, 2012 at 4:45 PM, Joseph Voelkel <[email protected]> wrote:

> # from  help(data.table)****
>
> DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)****
>
> DT[,lapply(.SD,sum),by=x]  # this works fine****
>
> ** **
>
> # but this fails****
>
> DT[,lapply(.SD,sum)]****
>
> # with this message: Error in lapply(.SD, sum) : object '.SD' not found***
> *
>
> ** **
>
> # Am I missing something obvious here?****
>
> ** **
>
> _______________________________________________
> datatable-help mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to