Suppose I have a data.table created as follows:
dt <- data.table(x1 = 1:10, x2 = 10:1, x3 = 1:10)
I need to do calculations with dynamically determined symbols within j like
Two approaches can do the work:
> dt[, get(s1) * get(s2)]
[1] 10 18 24 28 30 30 28 24 18 10
> dt[, .SD[[1]] * .SD[[2]], .SDcols = c(s1, s2)]
[1] 10 18 24 28 30 30 28 24 18 10
But if the data is very big and by= is used, the performance can significantly decay. Also the first approach using get() has scoping problem if s1 or s2 are themselves columns of dt.
Is there any possibility that makes it easier to use dynamically determined symbol without such significant performance decay and scoping problem?
For example, something like
which is inspired by the ..x notation introduced lately.
Suppose I have a
data.tablecreated as follows:I need to do calculations with dynamically determined symbols within
jlikeTwo approaches can do the work:
But if the data is very big and
by=is used, the performance can significantly decay. Also the first approach usingget()has scoping problem ifs1ors2are themselves columns ofdt.Is there any possibility that makes it easier to use dynamically determined symbol without such significant performance decay and scoping problem?
For example, something like
which is inspired by the
..xnotation introduced lately.