My questions is related to this one:
Turn vector output into columns in data.table?
But my situation is a bit more complicated. I am not only returning the vector as the columns, but I am also calculating other columns at the same time. E.g.:
DT = data.table(X = 1:10, Y = 11:20, Z = 21:30, group = rep(1:10, each = 3))
featuresDT <- quote(list(x = mean(X),
y = mean(Y),
z = mean(Z),
as.list(quantile(X))))
DT[, eval(featuresDT), by = "group"]
where quantile
returns a length 5 vector. Instead of getting a data.table with 8 columns, I am getting one with 4 columns and the quantile
results are displayed as extra rows and x, y and z
are duplicated 5 times. I also tried dist = as.list(quantile(X)
but that gives the same result but different column name.