Skip to content
Back to formatted view

Raw Message

Message-ID: <CAE2FW2=QOrHTkGjy3xUin6NdMnq=z09PTSE_cGfcQVL5gf6sAQ@mail.gmail.com>
Date: 2017-02-19T19:37:13Z
From: C W
Subject: Confused about using data.table package,

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)

#drop column w

df_1 <- df[, w := NULL] # I thought you are supposed to do: df_1 <- df[, -w]

df_2 <- df[x<y] # aren't you supposed to do df_2 <- df[x<y]?

df_3 <- df[, a := x-y] # created new column a using x minus y, why are we
using colon equals?

I am a bit confused by this syntax.

Thanks!

	[[alternative HTML version deleted]]