Get startedGet started for free

Helpers for filtering

1. Helpers for filtering

In this lesson, we will look at three functions that make subsetting operations far more convenient in data tables.

2. %like%

A commonly occurring subsetting operation is to look for all rows that match a pattern in a column. data table provides a convenience function percent like percent that is concise and also makes the actual operation easier to understand. In this example, we are looking for all the rows where start_station starts with the string San Francisco. The meta-character caret (^) specifies that you are looking for a pattern at the beginning of a string.

3. %between%

Percent between percent is a helper function that works on numeric columns. It searches for all values in the closed interval val1 and val2, that is, it finds all values that are greater than or equal to val1 and less than or equal to val2. It is also internally optimized to run in parallel wherever possible. Here we subset all rows where duration is between 2000 and 3000.

4. %chin%

Percent chin percent is another helper function which is a much more efficient version of percent in percent but only for character vectors. You can use it to look for specific strings in a vector. For example, here we subset all rows where start_station is either "Japantown", "Mezes Park", or "MLK Library".

5. Let's practice!

Go ahead and practice using these helper functions.