To filter the nycflights13 dataset by the month of July in R, we can use the filter()
function from the dplyr package.
Here's the code:
main.r173 chars5 lines
In the code above, we first loaded the necessary packages: dplyr
and nycflights13
. Then, we used the filter()
function to create a new dataset july_flights
that only contains flights that occurred in July. We specified the condition for filtering with month == 7
.
Note that month
is a variable in the nycflights13
dataset that contains the integer representation of the month (1 = January, 2 = February, etc.). So, to filter by the month of July, we need to use month == 7
.
gistlibby LogSnag