hf_pss <- hf[, .(platelets, serum_creatinine, serum_sodium)]
# also
hf_pss <- hf[, list(platelets, serum_creatinine, serum_sodium)]
7 Select
7.1 Select columns with data.table
7.1.1 Example
To select columns age
, sex
, and smoking
, you can use the following:
Explanation
Solution:
In data.table
, we refer to column names directly without using quotes. To select columns, we use the j
argument of the data.table
syntax, which is a list of column names to select. In data.table, the .()
notation is a shorthand for list()
.
For more information, see ?data.table::\\
[.data.table`.