Hi,<br><br>I have just noticed and installed your package and am trying to understand how it works.<br>The commented part in the following example from the reference manual (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>It is the last line that gives the following error:<br>Error in `[.data.table`(dt, , transform, c = max(b), by = "a") : <br> unused argument(s) (c = max(b))<br>
<br>Actually, I have a large data set where I use ave function. Unfortunately,<br>it is time consuming. This is why I want to try data.table. I have the following <br>data frame:<br><br>set.seed(1)<br>v1 <- c(rep(10, 3), rep(11, 2),rep(12, 2))<br>
v2 <- sample(5:10, 7, replace = T)<br>
v3 <- c(0, 1, 2, 0, 2,2,1)<br>
df <- data.frame(v1, v2, v3)<br>
df<br> v1 v2 v3<br>1 10 6 0<br>2 10 7 1<br>3 10 8 2<br>4 11 10 0<br>5 11 6 2<br>6 12 10 2<br>7 12 10 1<br>I want to add a new column v4 such that its values are equal to the value<br>of v2 if v3=0 and NA if v3=0 does not in each subgroup of v1. In the above example,<br>
the final result should be like<br> v1 v2 v3 v4<br>1 10 6 0 6<br>2 10 7 1 6<br>3 10 8 2 6<br>4 11 10 0 7<br>5 11 6 2 7<br>6 12 10 2 NA<br>7 12 10 1 NA<br><br>Thank you very much,<br><br>ozan bakis<br><br>