I want to combine a column of the data table R, but specifying the column names as strings. Is it possible to do this using the capabilities of data tables?
For example, I want to reproduce:
foo[,newcol:=mean(oldcol), by=id]
but using strings for column names, for example:
foo[,"newcol":=mean("oldcol"), by="id"]
I tried:
foo[,"newcol":=mean(foo[["oldcol"]]), by="id"]
which works, but it is slow since it does not fully use the data table.
Thank!
kahlo source
share