The group_by() function groups the data by a given set of columns.We want to obtain the number of departing flights per airport across the year. Edward Lawrence Logan International Airport Edward Lawrence Logan International AirportĤ 1 Gen. Edward Lawrence Logan International Airportģ 0 Gen. Edward Lawrence Logan International AirportĢ 0 Gen. Origin_airport destination_airport airline flight_number scheduled_departure departure_delayġ 0 Gen. Result % merge(airports_df, by.x = 'origin_airport', by.y = 'iata_code') > head(result) It is good to note that if those keys had the same name, it would have been possible to have the single argument by along with the name of that key. The keys on which the data frames are being joined on are specified in the by.x and by.y arguments.The flights_df data frame is joined with airports_df by using the merge() function.In order to do that, we note the following: We want to obtain the airport name corresponding to the airport code attached to flights. In this part, we will explore the data from different angles using basic data frame manipulation techniques with the dplyr library. Also, we see that the NA problem has been solved, and that the is_delayed statistics gives away that roughly 20% of flights according to our definition of delay. :1.0000įrom the summary output above, the dataset is now down to 585k observations. Scheduled_departure departure_delay is_delayed Mode :character Mode :character Mode :character Mode :character Length:585905 Length:585905 Length:585905 Length:585905Ĭlass :character Class :character Class :character Class :character TRUE ~ 0)) %>% # Remove redundant columns select( -year, -month, -day) > summary(flights_df)ĭestination_airport origin_airport airline flight_number Is_delayed = case_when(departure_delay >= 15 ~ 1, Scheduled_departure = convert_to_POSIXct(year, month, day, scheduled_departure), (departure_delay % # Fix columns mutate(flight_number = as.character(flight_number),
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |