Displaying 1 result from an estimated 1 matches for "demo_tmp".
Did you mean:
demo_app
2017 Dec 14
1
Aggregation across two variables in data.table
...pairs of two
demographics.
For 1 demographic this is straightforward:
Demo_names <- c("Age", "Education", "Marital", "Familysize", "Income",
"Housing")
means1 <- as.list(rep(0, length(Demo_names)))
for (i in 1:length(Demo_names)) {
Demo_tmp <- Demo_names[i]
means1[[i]] <- data_tmp[,list(mean(Theta)),by=Demo_tmp]}
Is there an easy way to extent this logic to more than 1 variable? I know
how to do this manually, e.g.,
data_tmp[,list(mean(Theta)),by=list(Marital, Education)]
But I don't know how to integrate this into a loop....