hf_high_creat <- hf[serum_creatinine > 1.4]
6 Filter
6.1 Introduction
Filtering a dataset is the process of indexing a subset of the cases, i.e. rows.
6.2 Filter rows with data.table
6.2.1 Example
To filter the hf
dataset to only include rows where age
is greater than 60, we can use the following code:
Explanation
Solution:
In data.table
, we refer to column names directly without using quotes. In contrast to data.frames, we donβt need to include a comma after filtering rows in the i
argument, but it would work just the same if we did, for example:
hf_high_creat <- hf[serum_creatinine > 1.4, ]
For more information, see ?data.table::`[.data.table`
.