Exercise

# Adding, updating and removing columns

As you now know, `:=`

is defined for use in `j`

only, and is used to update data.tables by reference. One way of using `:=`

is the `LHS := RHS`

form, where LHS is a character vector of columns (referenced by name or number) you wish to update and RHS is the corresponding value for each column (Note: LHS stands for "left hand side" and RHS stands for "right hand side" in what follows).

For example, the following line multiplies every row of column `C`

by 10 and stores the result in `C`

:

```
DT[, C := C * 10]
```

This first exercise will thoroughly test your understanding of `:=`

used in the `LHS := RHS`

form. It's time for you to show off your knowledge! A data.table `DT`

has been defined for you in the sample code.

Instructions

**100 XP**

- Add a column to
`DT`

by reference, named`Total`

, that contains`sum(B)`

for each group in column`A`

. - Add
`1L`

to the values in column`B`

, but only in the rows 2 and 4. - Add a new column
`Total2`

that contains`sum(B)`

grouped by`A`

but just over rows 2, 3 and 4. - Remove the
`Total`

column from`DT`

. - Use
`[[`

to select the third column as a vector. Simply print it out to the console.