In R, the filter()
function is used to subset data frames based on specific criteria.
Here is an example of how to use the filter()
function to subset rows from a data frame where a particular condition is satisfied:
main.r308 chars16 lines
This will result in the following output:
main.r54 chars4 lines
In the above example, we loaded the dplyr package, created a sample data frame, and then used the filter()
function to subset rows where the age
column is greater than 30. The filtered data frame is stored in a new object df_filtered
, which we can view to confirm that the rows have been filtered correctly.
gistlibby LogSnag