[datatable-help] Fwd: Sum on colunms by a reference column

Emmanuel Blondel emmanuel.blondel1 at gmail.com
Thu Jul 21 15:39:17 CEST 2011


Thanks Steve,

Though it is slower yes, it corresponds to what I was looking for. I 
don't work with a very large amount of data, so the second option is 
appropriate for me, at least at this stage.
Thanks a lot again,

Regards,
Emmanuel

Le 21/07/2011 15:15, Steve Lianoglou a écrit :
> Hi,
>
> On Thu, Jul 21, 2011 at 3:27 AM, Emmanuel Blondel
> <emmanuel.blondel1 at gmail.com>  wrote:
>> Dear all,
>>
>> I have a datatable (mydt) with a reference column (code) for which I set a
>> key, and a set of numeric columns (A ,B, C, D, E).
>> I obtain this from a serie of script codes, but the issue is that I have
>> duplicated rows (code), So i want to do is according to codestation, for
>> each of the columns..
>>
>> I could do the following code for one single column:
>> result<-mydt[,sum(A),by=code]
>>
>> but I would like to know if it is possible to do it for each of the columns,
>> so I get a databable with the same columns with sum value, group by
>> codestation. Do you have any suggestion?
> Do you mean something like:
>
> R>  mydt[, list(A=sum(A), B=sum(B), C=sum(C), D=sum(D), E=sum(E)), by=code]
>
> or equivalently, but maybe slower (there is a recent thread on the
> list about this):
>
> R>  mydt[, lapply(.SD, sum), by=code]
>
> Is that what you are after?
>
> -steve
>


-- 
*Emmanuel Blondel*
GIS Consultant

Geographic Information Systems
in Agronomy - Environment -Fisheries
Email: emmanuel.blondel1 at gmail.com - Emmanuel.Blondel at fao.org
Phone: +33 (0) 6 45 97 87 52
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20110721/5ee98366/attachment.htm>


More information about the datatable-help mailing list