Dear all,

I'm trying to use data.table to summarise a table and merge it to another 
table. Here is what I would like to do, but by using data.table() in a proper 
way.

library(data.table)
tab1 <- data.table(ID = 11:20, A = rnorm(10), D = 1:10, key = "ID")
tab2 <- data.table(ID2 = 1:10, D = rep(1:5, 2), B = rnorm(10), key = "ID2")
junk <- aggregate(tab2[, B], by = list(D = tab2[, D]), FUN = sum)
merge(tab1, junk, by = "D", all.x = TRUE)

This my attempt using data.table()

junk <- tab2[, mean(B), by = D]
tab1[junk]

Best regards,

Thierry



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to