Thank you very much...<br>ozan<br><br><div class="gmail_quote">On 24 May 2010 17:38, Short, Tom <span dir="ltr"><<a href="mailto:TShort@epri.com">TShort@epri.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> From: <a href="mailto:datatable-help-bounces@lists.r-forge.r-project.org">datatable-help-bounces@lists.r-forge.r-project.org</a><br>
[mailto:<a href="mailto:datatable-help-bounces@lists.r-forge.r-project.org">datatable-help-bounces@lists.r-forge.r-project.org</a>] On Behalf Of<br>
Ozan Bakis<br>
> Sent: Monday, May 24, 2010 10:12<br>
> To: <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
> Subject: [datatable-help] data.table question: ave like behavior<br>
<div class="im">><br>
><br>
> Hi,<br>
><br>
> I have just noticed and installed your package and am trying to<br>
understand how it works.<br>
> The commented part in the following example from the reference manual<br>
(p. 20) gives an error.<br>
><br>
> dt <- data.table(a=rep(1:5, 1), b=1:10)<br>
> transform(dt, c = a^2)<br>
> within(dt, {<br>
> b <- rev(b)<br>
> c <- a^2<br>
> rm(a)<br>
> })<br>
> dt[, transform, c = max(b), by="a"] # like "ave<br>
><br>
<br>
</div>Ozan, we experimented with that syntax for a while, but it was<br>
slow, so we took it out. The new syntax is as follows:<br>
<br>
dt[, transform(.SD, c = max(b)), by = a]<br>
<br>
.SD is a datatable of the subset, so you can manipulate that, in<br>
this case with transform.<br>
<br>
Another way to get ave functionality is:<br>
<br>
dt$c <- dt[, rep(max(b), length(a)), by = a]$V1<br>
<br>
This may be a little faster and more memory friendly (and maybe<br>
harder to read).<br>
<br>
You should be able to adapt either approach to the second part of<br>
your email.<br>
<font color="#888888"><br>
- Tom<br>
</font></blockquote></div><br>