You can filter
rows as a function of the content of a row using the filter()
function. (Recall from the previous chapters that you used filtering steps to remove outliers and NA
values.)
In the filter()
function, each of the arguments following the first is what the documentation refers to as a logical predicate. In other words, each of the arguments are assertions that some logical expression should be true.
The logical expressions used for filtering are defined in terms of the column names of the input dataframe. Here are some possible examples of logical predicates that could be used as arguments to the filter()
function:
column.name > 6
column.name == "abc"
!is.na( column.name )
A good application of the filter()
function to the fuel economy dataset could be to find data for just one model. There is likely a lot of variation in the fuel economy data from model to model, so we could get a more consistent result by just focusing on one model.
In the following...