Hi, I am new to this package and not sure how to implement the
sample() function with data.table.<br>
<br>
I have a data frame SPF with three columns cat, pnvid and wdpaint.
The pnvid variables has values 1:3, the wdpaint has values 1:10. I
am interested in the count of all combinations of wdpaint and pnvid
in my data set, which can be calculated using table or tapply (I use
the latter in the example code below). <br>
<br>
Normally I would use something like:<br>
<br>
<i>c <- tapply(SPF$cat, list(as.factor(SPF$pnvid),
as.factor(SPF$wdpaint), function(x) length(x))</i><br>
<br>
If I understand correctly, I would use the below when working with
data tables:<br>
<br>
<i>f <- SPF[,length(cat),by="wdpaint,pnvid"]</i><br>
<br>
But what if I want to reshuffle the column wdpaint first? When using
tapply, it would be something along the lines of:<br>
<br>
<i>a <- list(as.factor(SPF$pnvid), as.factor(sample(SPF$wdpaint,
replace=F)))<br>
c <- tapply(SPF$cat, a, function(x) length(x))</i><br>
<br>
<br>
But how to do this with data.table?<br><br>Paulo<br>