Skip to content
Back to formatted view

Raw Message

Message-ID: <CABdHhvGrs4JJszrRQzORR+ZAi24Dt-2tHu2gqOnZoE6PRRz2jg@mail.gmail.com>
Date: 2017-02-20T16:12:23Z
From: Hadley Wickham
Subject: Confused about using data.table package,
In-Reply-To: <F2C4B71E-3912-4BF8-9870-2ADCA5BB53EE@comcast.net>

On Sun, Feb 19, 2017 at 3:01 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
>> On Feb 19, 2017, at 11:37 AM, C W <tmrsg11 at gmail.com> wrote:
>>
>> Hi R,
>>
>> I am a little confused by the data.table package.
>>
>> library(data.table)
>>
>> df <- data.frame(w=rnorm(20, -10, 1), x= rnorm(20, 0, 1), y=rnorm(20, 10, 1),
>> z=rnorm(20, 20, 1))
>>
>> df <- data.table(df)
>
>   df <- setDT(df) is preferred.

Don't you mean just

setDT(df)

?

setDT() modifies by reference.

>>
>> df_3 <- df[, a := x-y] # created new column a using x minus y, why are we
>> using colon equals?
>
> You need to do more study of the extensive documentation. The behavior of the ":=" function is discussed in detail there.

You can get to that documentation with ?":="

Hadley

-- 
http://hadley.nz