Question 1

flights <- nycflights13::flights

late_flights <- flights %>%
  filter(arr_delay > 5)

monthly_late_flights <- late_flights %>%
  group_by(month) %>%
  summarize(count = n())
print(monthly_late_flights)
## # A tibble: 12 × 2
##    month count
##    <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

Question 2

monthly_traffic <- flights %>%
  group_by(month, carrier) %>%
  summarise(n_flights = n()) %>%
  mutate(percent_traffic = n_flights / sum(n_flights) * 100) 
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.
print(monthly_traffic)
## # A tibble: 185 × 4
## # Groups:   month [12]
##    month carrier n_flights percent_traffic
##    <int> <chr>       <int>           <dbl>
##  1     1 9E           1573           5.83 
##  2     1 AA           2794          10.3  
##  3     1 AS             62           0.230
##  4     1 B6           4427          16.4  
##  5     1 DL           3690          13.7  
##  6     1 EV           4171          15.4  
##  7     1 F9             59           0.218
##  8     1 FL            328           1.21 
##  9     1 HA             31           0.115
## 10     1 MQ           2271           8.41 
## # ℹ 175 more rows

Question 3

flights <- flights %>%
  mutate(dep_date = make_date(year, month, day))


last_flights_each_month <- flights %>%
  filter(day == days_in_month(dep_date)) %>%
  group_by(month) %>%
  slice_max(dep_time)


print(last_flights_each_month)
## # A tibble: 14 × 20
## # Groups:   month [12]
##     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    31     2354           2055       179      144           2250
##  2  2013     2    28     2359           2359         0      443            438
##  3  2013     3    31     2358           2359        -1      332            339
##  4  2013     4    30     2351           2359        -8      345            339
##  5  2013     5    31     2355           2359        -4      338            350
##  6  2013     5    31     2355           2359        -4      335            345
##  7  2013     6    30     2359           2110       169      118           2243
##  8  2013     7    31     2352           2245        67       49           2359
##  9  2013     8    31     2359           2359         0      345            350
## 10  2013     8    31     2359           2359         0      346            340
## 11  2013     9    30     2349           2359       -10      325            350
## 12  2013    10    31     2357           2359        -2      345            345
## 13  2013    11    30     2354           2359        -5      430            440
## 14  2013    12    31     2356           2359        -3      436            445
## # ℹ 12 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>, dep_date <date>

question 4

Choiceresponse <- read.csv("multipleChoiceResponses1.csv")
usefulness_count <- Choiceresponse %>%
  select(starts_with("LearningPlatformUsefulness")) %>%
  gather(key = "learning_platform", value = "usefulness") %>%
  filter(!is.na(usefulness)) %>%
  group_by(learning_platform, usefulness) %>%
  summarise(count = n(), .groups = 'drop')

# Remove "LearningPlatformUsefulness" from each string in learning_platform
usefulness_count$learning_platform <- sub("LearningPlatformUsefulness", "", usefulness_count$learning_platform)

print(usefulness_count)
## # A tibble: 54 × 3
##    learning_platform usefulness      count
##    <chr>             <chr>           <int>
##  1 Arxiv             Not Useful         37
##  2 Arxiv             Somewhat useful  1038
##  3 Arxiv             Very useful      1316
##  4 Blogs             Not Useful         45
##  5 Blogs             Somewhat useful  2406
##  6 Blogs             Very useful      2314
##  7 College           Not Useful        101
##  8 College           Somewhat useful  1405
##  9 College           Very useful      1853
## 10 Communities       Not Useful         16
## # ℹ 44 more rows

question 5

selected_data <- Choiceresponse %>% select(starts_with("LearningPlatformUsefulness"))

long_data <- selected_data %>% 
  pivot_longer(cols = everything(), names_to = "learning_platform", values_to = "usefulness") %>%
  filter(!is.na(usefulness))

long_data$learning_platform <- sub("LearningPlatformUsefulness", "", long_data$learning_platform)

result <- long_data %>%
  group_by(learning_platform) %>%
  summarise(
    count = n(),
    tot = sum(usefulness != "Not Useful"),
    perc_usefulness = tot / count
  )
print(result)
## # A tibble: 18 × 4
##    learning_platform count   tot perc_usefulness
##    <chr>             <int> <int>           <dbl>
##  1 Arxiv              2391  2354           0.985
##  2 Blogs              4765  4720           0.991
##  3 College            3359  3258           0.970
##  4 Communities        1142  1126           0.986
##  5 Company             981   940           0.958
##  6 Conferences        2182  2063           0.945
##  7 Courses            5992  5945           0.992
##  8 Documentation      2321  2279           0.982
##  9 Friends            1581  1530           0.968
## 10 Kaggle             6583  6527           0.991
## 11 Newsletters        1089  1033           0.949
## 12 Podcasts           1214  1090           0.898
## 13 Projects           4794  4755           0.992
## 14 SO                 5640  5576           0.989
## 15 Textbook           4181  4112           0.983
## 16 TradeBook           333   324           0.973
## 17 Tutoring           1426  1394           0.978
## 18 YouTube            5229  5125           0.980

##Question 6

library(ggplot2)
library(forcats)

ggplot(result, aes(x = fct_reorder(learning_platform, perc_usefulness), y = perc_usefulness)) +
  geom_col() +
  coord_flip()

  labs(
    x = "Learning Platform",
    y = "Percentage of 'Useful' or 'Very Useful' Responses",
    title = "Usefulness Ratings of Learning Platforms"
  ) +
  theme_minimal()
## NULL

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: