![]() ![]() 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. If you click on the max_delay column header, you should see that the maximum departure delay for PDX was in March and for Seattle was in May. The created table in HTML is available here. (An excellent tutorial on DT is available at. Go ahead and play around with the filter boxes at the top of each column too. I’ve specified a few extra options here to show all 12 months by default and to automatically set the width. The DT package provides a nice interface for viewing data frames in R. Summarize(max_delay = max(dep_delay, na.rm = TRUE)) dep_delays_by_month % group_by(origin, month) %>% In order to answer the second question, we’ll again make use of the various functions in the dplyr package. 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)) %>% # List of packages required for this analysis We begin by ensuring the needed packages are installed and then load them into our R session. (More information and the source code for this R package is available at. In what follows, I’ll discuss these different options using data on departing flights from Seattle and Portland in 2014. One of the neat tools available via a variety of packages in R is the creation of beautiful tables using data frames stored in R. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |