Slice assignment of .table data in R

To read the data.table slice, I can use the following syntax:

foo = DT[, 5:10, with=F]

but now I want to do:

foo = foo + 1
DT[, 5:10, with=F] = foo

This does not work; referring to columns by name also doesn't work. Any suggestions?

+4
source share
1 answer

It is a little more subtle. This is how I read your question and how you are trying to do it at the moment ...

Your first row creates a new object data.tablewith a 6-column subset of columns:

foo = DT[, 5:10, with=F]

I immediately think about the implications for memory. If each column is 1 GB, then the new selected object is 6 GB in size.

then you are +1 to everything in this 6GB:

foo = foo + 1   # or something like that, that works

This is a copy of this 6 GB to another new 6 GB.

6GB foo , DT, :

DT[, 5:10, with=F] = foo    # or something like that, that works

. .

data.table , set. .

for (col in 5:10)
    set(DT, j=col, value=DT[[col]]+1)

. DT[[col]] ( data.table, R, ). +1 . , , , , +1 .

+5

All Articles