We add in a few options to make the output of the table a little nicer by specifying horizontal lines and removing the default rownames. We will then make a call to the multirow function in \(\LaTeX\) in a sneaky way of pasting the appropriate text in addition to using the force option for sanitizing the text into \(\LaTeX\). It counts how many times a value is repeated in a table. Awesomely enough, the rle function in R will be of great help to us in this endeavor. With the originating airport duplicating across all of the airlines, it would be nice if we could reduce this duplication and just bold PDX or SEA and have each appear once. If you don’t know \(\LaTeX\), I’ve also duplicated a similar table using kable for you to compare: kable(by_airline) origin \\Ģ2 & SEA & HA & 730 & Hawaiian Airlines Inc. \\Ģ0 & SEA & B6 & 2253 & JetBlue Airways \\Ģ1 & SEA & F9 & 1336 & Frontier Airlines Inc. \\ġ7 & SEA & AA & 5399 & American Airlines Inc. \\ġ6 & SEA & OO & 8869 & SkyWest Airlines Inc. \\ġ5 & SEA & UA & 10610 & United Air Lines Inc. \\ġ4 & SEA & DL & 11548 & Delta Air Lines Inc. \\ġ3 & SEA & WN & 12162 & Southwest Airlines Co. \\ġ2 & SEA & AS & 49616 & Alaska Airlines Inc. \\ġ1 & PDX & HA & 365 & Hawaiian Airlines Inc. \\Ĩ & PDX & F9 & 1362 & Frontier Airlines Inc. \\ħ & PDX & AA & 2187 & American Airlines Inc. \\ĥ & PDX & DL & 5168 & Delta Air Lines Inc. \\Ĥ & PDX & UA & 6061 & United Air Lines Inc. \\ģ & PDX & OO & 9841 & SkyWest Airlines Inc. \\Ģ & PDX & WN & 11193 & Southwest Airlines Co. print(xtable(by_airline),ġ & PDX & AS & 12844 & Alaska Airlines Inc. We will focus on producing the \(\LaTeX\) code in this example. The xtable package and its xtable function (and also the kable function you saw earlier) provide the functionality to generate HTML code or \(\LaTeX\) code to produce a table. data("airlines", package = "pnwflights14")īy_airline % group_by(origin, carrier) %>% We merge the flights data with the airlines data to get the names of the airlines from the two letter carrier code. The xtable package to produce nice tables in a PDFĪgain, we find ourselves using the extremely helpful dplyr package to answer this question and to create the underpinnings of our table to display. Surprisingly, the airport in Bellingham, WA (only around 100 miles north of SEA) had the fifth largest mean arrival delay. Houston also had around a 10 minute delay on average. Oddly enough, flights to Cleveland (from PDX and SEA) had the worst arrival delays in 2014. Lastly we output this table cleanly using the kable function. Rename("Airport Name" = name, "Airport Code" = dest, "Mean Arrival Delay" = mean_arr_delay) data("airports", package = "pnwflights14") Here we will do a match to identify the names of these airports using the inner_join function in dplyr. One of the other data sets included in the pnwflights14 package is airports that lists the names. This information is helpful but you may not necessarily know to which airport each of these FAA airport codes refers. Summarize(mean_arr_delay = mean(arr_delay, na.rm = TRUE)) %>% We’ll use the top_n function to isolate the 5 worst mean arrival delays. To address the first question, we will use the dplyr package written by Hadley Wickham as below. How many flights departed for each airline from each of the airports? How does the maximum departure delay vary by month for each of the two airports?ģ. Which destinations had the worst arrival delays (on average) from the two PNW airports?Ģ. The questions I will analyze by creating tables areġ. Here I will delve further into some of the questions I addressed in two recent workshops I led in the Fall 2015 Data Reed Research Skills Workshop Series. The dataset provides for the development of a lot of interesting questions. # Install Chester's pnwflights14 package (if not already)ĭevtools::install_github("ismayc/pnwflights14")ĭata("flights", package = "pnwflights14") # If there are any packages in the list that aren't installed, # names of the packages not installed to the variable new.pkg # Check if packages are not installed and assign the # List of packages required for this analysis
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |