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(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
# Read the CSV file
data <- read.csv("multipleChoiceResponses1.csv")


##Count the usefulness by learning platform.
usefulness_by_platform <- data %>% select(starts_with("LearningPlatformUsefulness")) %>%  
  set_names(names(.) %>% str_replace("LearningPlatformUsefulness", "")) %>% 
  gather(key = "learning_platform", value = "usefulness",convert = FALSE, na.rm = TRUE)

usefulness_by_platform %>% group_by(learning_platform, usefulness) %>% 
  summarise(n = n()) %>% 
  ungroup()
## `summarise()` has grouped output by 'learning_platform'. You can override using
## the `.groups` argument.
## # A tibble: 54 × 3
##    learning_platform usefulness          n
##    <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
##Compute the number of total reponses and number of reponses which are atleast useful.
#Calculate the number of total responses by learning platform

total_usefulness_by_platform <- usefulness_by_platform %>% 
  group_by(learning_platform) %>% 
  summarise(tot = n())

#Calculate the number of useful responses by learning platform

usefulness_count <- usefulness_by_platform %>% 
  filter(!grepl("Not Useful",usefulness,ignore.case = TRUE)) %>% 
  group_by(learning_platform) %>% 
  summarise(count = n())

#Calculate the percentage of usefulness for each learning platform

perc_usefulness <- usefulness_count %>% 
  left_join(total_usefulness_by_platform, by = "learning_platform") %>% 
  mutate(perc_usefulness = count/tot) %>% 
  mutate(perc_usefulness = round(perc_usefulness, digits = 3))

#Print the result

perc_usefulness
## # A tibble: 18 × 4
##    learning_platform count   tot perc_usefulness
##    <chr>             <int> <int>           <dbl>
##  1 Arxiv              2354  2391           0.985
##  2 Blogs              4720  4765           0.991
##  3 College            3258  3359           0.97 
##  4 Communities        1126  1142           0.986
##  5 Company             940   981           0.958
##  6 Conferences        2063  2182           0.945
##  7 Courses            5945  5992           0.992
##  8 Documentation      2279  2321           0.982
##  9 Friends            1530  1581           0.968
## 10 Kaggle             6527  6583           0.991
## 11 Newsletters        1033  1089           0.949
## 12 Podcasts           1090  1214           0.898
## 13 Projects           4755  4794           0.992
## 14 SO                 5576  5640           0.989
## 15 Textbook           4112  4181           0.983
## 16 TradeBook           324   333           0.973
## 17 Tutoring           1394  1426           0.978
## 18 YouTube            5125  5229           0.98
##Based on previous results, select the first two columnslearning_platformandcount
# Order learning_platform by count in descending order
usefulness_count <- usefulness_count %>%
  arrange(desc(count))

# Select top 10 platforms and calculate their cumulative percentage
# Order learning_platform by count in descending order
usefulness_count <- usefulness_count %>%
  arrange(desc(count))

# Calculate cumulative percentage
usefulness_count <- usefulness_count %>%
  mutate(
    cum_pct = cumsum(count) / sum(count)
  )

# Select top 10 platforms
top_10_platforms <- usefulness_count %>%
  slice_max(order_by = count, n = 10)

# Calculate 'Other' cumulative percentage
other_cum_pct <- usefulness_count %>%
  filter(!(learning_platform %in% top_10_platforms$learning_platform)) %>%
  summarise(
    count = sum(count),
    cum_pct = 1
  ) %>%
  mutate(
    learning_platform = "Other"
  )

# Combine top 10 and 'Other' platforms
result <- bind_rows(top_10_platforms, other_cum_pct) %>%
  select(learning_platform, count, cum_pct)

# Display the top 10 useful learning platforms along with cumulative percentages
print(result)
## # A tibble: 11 × 3
##    learning_platform count cum_pct
##    <chr>             <int>   <dbl>
##  1 Kaggle             6527   0.121
##  2 Courses            5945   0.230
##  3 SO                 5576   0.333
##  4 YouTube            5125   0.428
##  5 Projects           4755   0.516
##  6 Blogs              4720   0.603
##  7 Textbook           4112   0.679
##  8 College            3258   0.739
##  9 Arxiv              2354   0.782
## 10 Documentation      2279   0.825
## 11 Other              9500   1
## Assuming you have a data frame named result with columns learning_platform, count, and cum_pct
# Order the 'result' data frame to ensure the correct display in the boxplot
result <- result %>%
  mutate(learning_platform = factor(learning_platform, levels = rev(unique(learning_platform))))

# Create a horizontal side-by-side boxplot
ggplot(result, aes(x = count, y = learning_platform, fill = learning_platform)) +
  stat_boxplot(geom = "errorbarh", width = 0.5) +
  labs(
    title = "Top 10 Useful Learning Platforms - Counts",
    x = "Counts",
    y = "Learning Platforms"
  ) +
  theme_minimal() +
  theme(axis.text.y = element_text(hjust = 0)) +
  guides(fill = FALSE)
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

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.