To filter nycflights13
by month in R, we can use the filter()
function from the dplyr
package. First, we need to load the nycflights13
dataset into our environment. We can do that by running the following code:
main.r22 chars2 lines
Then, we can use filter()
to subset the dataset by month
. For example, if we want to get all flights that occurred in January, we can run:
main.r78 chars5 lines
In the code above, month == 1
is the condition we use to filter the dataset. We use the pipe operator %>%
to chain the filter()
function after loading the dataset, which makes the code more readable.
We can substitute 1
with any month number between 1 and 12 to filter by that month.
gistlibby LogSnag