R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

#install.packages("tintex")
#tinytex::install_tinytex()

# Load libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(nycflights13)
## Warning: package 'nycflights13' was built under R version 4.3.2
library(ggplot2)
library(forcats)
library(dplyr)
library(tidyquant)
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## 
## Attaching package: 'PerformanceAnalytics'
## 
## The following object is masked from 'package:graphics':
## 
##     legend
## 
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
multipleChoiceResponses <- read_csv("multipleChoiceResponses1.csv")
## Rows: 16716 Columns: 47
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (46): LearningPlatformUsefulnessArxiv, LearningPlatformUsefulnessBlogs, ...
## dbl  (1): Age
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data("flights")
names(flights)
##  [1] "year"           "month"          "day"            "dep_time"      
##  [5] "sched_dep_time" "dep_delay"      "arr_time"       "sched_arr_time"
##  [9] "arr_delay"      "carrier"        "flight"         "tailnum"       
## [13] "origin"         "dest"           "air_time"       "distance"      
## [17] "hour"           "minute"         "time_hour"
names(data)
## NULL
##Use theflightsdata from packagenycflights13to answer thefollowing questions
#How many flights arrived late each month? The late arrival is the flight arrivingmore than 5 minutes after its scheduled arrival time.
late_flights_per_month <- flights %>%
  mutate(late = arr_delay > 5) %>%
  group_by(month) %>%
  summarise(lateflights = sum(late, na.rm = TRUE))

late_flights_per_month
## # A tibble: 12 × 2
##    month lateflights
##    <int>       <int>
##  1     1        8988
##  2     2        8119
##  3     3        9033
##  4     4       10544
##  5     5        8490
##  6     6       10739
##  7     7       11518
##  8     8        9649
##  9     9        5347
## 10    10        7628
## 11    11        7485
## 12    12       12291
#What percentage of traffic did each carrier represent, by month?
# Calculate the number of flights for each carrier by month
flights_summary <- flights %>%
  group_by(month, carrier) %>%
  summarise(n_flights = n()) %>%
  ungroup()
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.
total_flights_per_month <- flights_summary %>%
  group_by(month) %>%
  summarise(total_flights = sum(n_flights))


traffic_percentage <- flights_summary %>%
  inner_join(total_flights_per_month, by = "month") %>%
  mutate(percentage = (n_flights / total_flights) * 100) %>%
  select(month, carrier, percentage)


traffic_percentage_pivot <- traffic_percentage %>%
  pivot_wider(names_from = month, values_from = percentage, names_prefix = 'Month_')

traffic_percentage_pivot
## # A tibble: 16 × 13
##    carrier  Month_1 Month_2 Month_3 Month_4 Month_5  Month_6 Month_7 Month_8
##    <chr>      <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    <dbl>   <dbl>   <dbl>
##  1 9E       5.83      5.85   5.64     5.33    5.08   5.09      5.08   4.96  
##  2 AA      10.3      10.1    9.67     9.61    9.73   9.76      9.79   9.74  
##  3 AS       0.230     0.224  0.215    0.212   0.215  0.212     0.211  0.211 
##  4 B6      16.4      16.4   16.5     15.9    15.9   16.4      16.9   16.9   
##  5 DL      13.7      13.8   14.5     14.4    14.2   14.6      14.4   14.7   
##  6 EV      15.4      15.3   16.4     16.1    16.7   15.8      15.8   15.6   
##  7 F9       0.218     0.196  0.198    0.201   0.201  0.195     0.197  0.188 
##  8 FL       1.21      1.19   1.10     1.10    1.13   0.892     0.894  0.897 
##  9 HA       0.115     0.112  0.108    0.106   0.108  0.106     0.105  0.106 
## 10 MQ       8.41      8.19   7.82     7.80    7.93   7.71      7.68   7.72  
## 11 OO       0.00370  NA     NA       NA      NA      0.00708  NA      0.0136
## 12 UA      17.2      17.4   17.2     17.8    17.2   17.6      17.2   17.5   
## 13 US       5.93      6.22   5.97     6.10    6.20   6.15      6.07   6.07  
## 14 VX       1.17      1.09   1.05     1.64    1.72   1.70      1.66   1.67  
## 15 WN       3.69      3.65   3.46     3.46    3.49   3.64      3.66   3.57  
## 16 YV       0.170     0.192  0.0624   0.134   0.170  0.173     0.275  0.222 
## # ℹ 4 more variables: Month_9 <dbl>, Month_10 <dbl>, Month_11 <dbl>,
## #   Month_12 <dbl>
#What was the latest flight to depart each month?
latest_departures <- flights %>%
  group_by(month) %>%
  slice_max(order_by = dep_time) %>%
  ungroup()
latest_departures   
## # A tibble: 35 × 19
##     year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time
##    <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>
##  1  2013     1     7     2359           2359         0      506            437
##  2  2013     1    12     2359           2359         0      429            437
##  3  2013     1    13     2359           2130       149      435            218
##  4  2013     1    18     2359           2359         0      439            437
##  5  2013     1    19     2359           2359         0      437            444
##  6  2013     1    25     2359           2359         0      500            444
##  7  2013     2     7     2400           2359         1      432            436
##  8  2013     2     7     2400           2359         1      443            444
##  9  2013     2    11     2400           2135       145      251             35
## 10  2013     3    15     2400           2359         1      324            338
## # ℹ 25 more rows
## # ℹ 11 more variables: arr_delay <dbl>, carrier <chr>, flight <int>,
## #   tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>,
## #   hour <dbl>, minute <dbl>, time_hour <dttm>
##Use themultipleChoiceResponses1.csvto answer the following questions:
#Count the usefulness by learning platform.

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.