Hi Gerald Jean,
Glad to hear it!
The number of elements in each group is contained in a special variable `.N`.
IIUC, all you’ve to do is replace ’n’ by ‘.N’ in your DT code.
BTW, we are also adding detailed (HTML) vignettes, which you can find here:
https://github.com/Rdatatable/data.table/wiki/Getting-started
You can see here: https://github.com/Rdatatable/data.table/issues/944 to get an
idea on the vignettes that are yet to be done.
Hope this is of some help.
--
Arun
On 16 Feb 2015 at 20:55:04, Gerald Jean ([email protected]) wrote:
Hello,
I am fairly new to data.table, it’s fast and I love it!!! Here is what I am
trying to do. Suppose I have a data.table DT, with columns a, b, c, v, t and
g. I want to add a new column, x, say, where for each group defined by g, in
vector notation:
x = c(0, (v[-1] – v[-n]) / (t[-1] – t[-n]))
where n is the number of rows for the groups, I don’t know n yet. Obviously
DT[, x := c(0, (v[-1] – v[-n]) / (t[-1] – t[-n])), by = g]
won’t work. I have read the doc I found so far but couldn’t find examples of
subsetting the groups, maybe it could be done using .SD but I am not familiar
enough with data.table yet to figure out how to do it.
By the way my data.tables are large, 50000 to over 1000000 rows and I have over
60000 of them to process and many more operations to perform, I just hope
data.table will do the trick!!!
Thanks for your help,
Gérald
Gerald Jean, M. Sc. en statistiques
Conseiller senior en statistiques
Actuariat corporatif,
Modélisation et Recherche
Assurance de dommages
Mouvement Desjardins
Lévis (siège social)
418 835-4900,
poste 5527639
1 877 835-4900,
poste 5527639
Télécopieur : 418 835-6657
Faites bonne impression et imprimez seulement au besoin!
Ce courriel est confidentiel, peut être protégé par le secret professionnel et
est adressé exclusivement au destinataire. Il est strictement interdit à toute
autre personne de diffuser, distribuer ou reproduire ce message. Si vous l'avez
reçu par erreur, veuillez immédiatement le détruire et aviser l'expéditeur.
Merci.
_______________________________________________
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