From 5f5f745000ccd0eb80d8ec4c609101d7ad9d5425 Mon Sep 17 00:00:00 2001 From: Stanley Zhao Date: Tue, 6 Oct 2020 11:14:56 +0800 Subject: [PATCH 1/7] Assignment 2 --- Assignment 2-2020.Rmd | 82 +++++- Assignment-2-2020.html | 643 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 712 insertions(+), 13 deletions(-) create mode 100644 Assignment-2-2020.html diff --git a/Assignment 2-2020.Rmd b/Assignment 2-2020.Rmd index 0b235a3..7fab49d 100644 --- a/Assignment 2-2020.Rmd +++ b/Assignment 2-2020.Rmd @@ -1,6 +1,6 @@ --- title: "Assignment 2" -author: "Charles Lang" +author: "Stanley Zhao" date: "September 24, 2020" output: html_document --- @@ -37,7 +37,7 @@ D2 <- filter(D1, year == 2018) hist(D2$watch.time) -#Change the number of breaks to 100, do you get the same impression? +#Change the number of breaks to 100, do you get the same impression? No hist(D2$watch.time, breaks = 100) @@ -91,17 +91,32 @@ pairs(D5) 1. Create a simulated data set containing 100 students, each with a score from 1-100 representing performance in an educational game. The scores should tend to cluster around 75. Also, each student should be given a classification that reflects one of four interest groups: sport, music, nature, literature. ```{r} -#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 20 -#pmax sets a maximum value, pmin sets a minimum value -#round rounds numbers to whole number values -#sample draws a random samples from the groups vector according to a uniform distribution +#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 15 +#filter() can be used to set a maximum and minimum value +#round() rounds numbers to whole number values +#sample() draws a random samples from the groups vector according to a uniform distribution +score <- rnorm(100, 75, 15) +hist(score,breaks = 30) +S1 <- data.frame(score) +library(dplyr) +S1 <- filter(S1, score <= 100) +hist(S1$score) + +S2 <- data.frame(rep(100,100-nrow(S1))) +names(S2) <- "score" +S3 <- bind_rows(S1,S2) +S3$score <- round(S3$score,0) +interest <- c("sport","music","nature","literature") +S3$interest <- sample(interest, 100, replace = TRUE) +S3$stid <- seq(1,100,1) ``` 2. Using base R commands, draw a histogram of the scores. Change the breaks in your histogram until you think they best represent your data. ```{r} +hist(S3$score, breaks = 10) ``` @@ -111,6 +126,8 @@ pairs(D5) ```{r} #cut() divides the range of scores into intervals and codes the values in scores according to which interval they fall. We use a vector called `letters` as the labels, `letters` is a vector made up of the letters of the alphabet. +lable <- letters[1:10] +S3$breaks <- cut(S3$score, breaks = 10, labels = lable) ``` 4. Now using the colorbrewer package (RColorBrewer; http://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3) design a pallette and assign it to the groups in your data on the histogram. @@ -118,12 +135,12 @@ pairs(D5) ```{r} library(RColorBrewer) #Let's look at the available palettes in RColorBrewer - +display.brewer.all() #The top section of palettes are sequential, the middle section are qualitative, and the lower section are diverging. #Make RColorBrewer palette available to R and assign to your bins - +S3$colors <- brewer.pal(10, "Spectral") #Use named palette in histogram - +hist(S3$score, col = S3$colors) ``` @@ -131,20 +148,24 @@ library(RColorBrewer) ```{r} #Make a vector of the colors from RColorBrewer +interest.col <- brewer.pal(4, "Dark2") +boxplot(score ~ interest, S3, col = interest.col) ``` 6. Now simulate a new variable that describes the number of logins that students made to the educational game. They should vary from 1-25. ```{r} - +S3$logins <- sample(1:25, 100, replace = TRUE) ``` 7. Plot the relationships between logins and scores. Give the plot a title and color the dots according to interest group. ```{r} +plot(S3$logins, S3$score, col = S3$colors, main = "Student Logins vs. Scores") +S3$col1 <- ifelse(S3$interest == "music", "red", "green") ``` @@ -152,14 +173,17 @@ library(RColorBrewer) 8. R contains several inbuilt data sets, one of these in called AirPassengers. Plot a line graph of the the airline passengers over time using this data set. ```{r} - +AP <- data.frame(AirPassengers) +plot(AirPassengers) ``` 9. Using another inbuilt data set, iris, plot the relationships between all of the variables in the data set. Which of these relationships is it appropraiet to run a correlation on? ```{r} - +IRIS <- data.frame(iris) +plot(iris) +#Petal.Length and Petal.Width is appropraiet to run a correlation. ``` # Part III - Analyzing Swirl @@ -171,7 +195,14 @@ In this repository you will find data describing Swirl activity from the class s ### Instructions 1. Insert a new code block +```{r} + +``` + 2. Create a data frame from the `swirl-data.csv` file called `DF1` +```{r} +DF1 <- read.csv("swirl-data.csv", header = TRUE) +``` The variables are: @@ -185,19 +216,44 @@ The variables are: `hash` - anonymyzed student ID 3. Create a new data frame that only includes the variables `hash`, `lesson_name` and `attempt` called `DF2` +```{r} +DF2 <- select(DF1, hash, lesson_name, attempt) +``` 4. Use the `group_by` function to create a data frame that sums all the attempts for each `hash` by each `lesson_name` called `DF3` +```{r} +DF3 <- DF2 %>% group_by(hash, lesson_name) %>% summarise(attempt = sum(attempt)) +``` 5. On a scrap piece of paper draw what you think `DF3` would look like if all the lesson names were column names - +![My Picture](Assignment 2 Part 3 Q5.jpeg) 6. Convert `DF3` to this format +```{r} +DF3 <- spread(DF3, lesson_name, attempt) +``` 7. Create a new data frame from `DF1` called `DF4` that only includes the variables `hash`, `lesson_name` and `correct` +```{r} +DF4 <- select(DF1, hash, lesson_name, correct) +``` 8. Convert the `correct` variable so that `TRUE` is coded as the **number** `1` and `FALSE` is coded as `0` +```{r} +DF4$correct <- ifelse(DF4$correct == TRUE, 1, 0) +``` 9. Create a new data frame called `DF5` that provides a mean score for each student on each course +```{r} +DF5 <- DF4 %>% group_by(hash, lesson_name) %>% summarise(mean.correct = mean(correct, na.rm = TRUE)) +``` 10. **Extra credit** Convert the `datetime` variable into month-day-year format and create a new data frame (`DF6`) that shows the average correct for each day +```{r} +DF1$datetime <- as.POSIXlt(DF1$datetime, origin = "1970-01-01") +DF1$datetime <- strftime(DF1$datetime, format = "%m:%d") +DF6 <- select(DF1, datetime, correct) +DF6$correct <- ifelse(DF6$correct == TRUE, 1, 0) +DF6 <- DF6 %>% group_by(datetime) %>% summarise(av.correct = mean(correct, na.rm = TRUE)) +``` Finally use the knitr function to generate an html document from your work. Commit, Push and Pull Request your work back to the main branch of the repository. Make sure you include both the .Rmd file and the .html file. diff --git a/Assignment-2-2020.html b/Assignment-2-2020.html new file mode 100644 index 0000000..65dff62 --- /dev/null +++ b/Assignment-2-2020.html @@ -0,0 +1,643 @@ + + + + + + + + + + + + + + + +Assignment 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +

#Part I

+
+

Data Wrangling

+

In the hackathon a project was proposed to collect data from student video watching, a sample of this data is available in the file video-data.csv.

+

stid = student id year = year student watched video participation = whether or not the student opened the video watch.time = how long the student watched the video for confusion.points = how many times a student rewatched a section of a video key,points = how many times a student skipped or increased the speed of a video

+
#Install the 'tidyverse' package or if that does not work, install the 'dplyr' and 'tidyr' packages.
+
+#Load the package(s) you just installed
+
+library(tidyverse)
+
## ─ Attaching packages ─────────────────────────── tidyverse 1.3.0 ─
+
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
+## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
+## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
+## ✓ readr   1.3.1     ✓ forcats 0.5.0
+
## ─ Conflicts ──────────────────────────── tidyverse_conflicts() ─
+## x dplyr::filter() masks stats::filter()
+## x dplyr::lag()    masks stats::lag()
+
library(tidyr)
+library(dplyr)
+
+D1 <- read.csv("video-data.csv", header = TRUE)
+
+#Create a data frame that only contains the years 2018
+D2 <- filter(D1, year == 2018)
+
+
+

Histograms

+
#Generate a histogram of the watch time for the year 2018
+
+hist(D2$watch.time)
+

+
#Change the number of breaks to 100, do you get the same impression? No
+
+hist(D2$watch.time, breaks = 100)
+

+
#Cut the y-axis off at 10
+
+hist(D2$watch.time, breaks = 100, ylim = c(0,10))
+

+
#Restore the y-axis and change the breaks so that they are 0-5, 5-20, 20-25, 25-35
+
+hist(D2$watch.time, breaks = c(0,5,20,25,35))
+

+
+
+

Plots

+
#Plot the number of confusion points against the watch time
+
+plot(D1$confusion.points, D1$watch.time)
+

+
#Create two variables x & y
+x <- c(1,3,2,7,6,4,4)
+y <- c(2,4,2,3,2,4,3)
+
+#Create a table from x & y
+table1 <- table(x,y)
+
+#Display the table as a Barplot
+barplot(table1)
+

+
#Create a data frame of the average total key points for each year and plot the two against each other as a lines
+
+D3 <- D1 %>% group_by(year) %>% summarise(mean_key = mean(key.points))
+
## `summarise()` ungrouping output (override with `.groups` argument)
+
plot(D3$year, D3$mean_key, type = "l", lty = "dashed")
+

+
#Create a boxplot of total enrollment for three students
+D4 <- filter(D1, stid == 4|stid == 20| stid == 22)
+#The drop levels command will remove all the schools from the variable with no data  
+D4 <- droplevels(D4)
+boxplot(D4$watch.time~D4$stid, xlab = "Student", ylab = "Watch Time")
+

## Pairs

+
#Use matrix notation to select columns 2, 5, 6, and 7
+D5 <- D1[,c(2,5,6,7)]
+#Draw a matrix of plots for every combination of variables
+pairs(D5)
+

## Part II

+
    +
  1. Create a simulated data set containing 100 students, each with a score from 1-100 representing performance in an educational game. The scores should tend to cluster around 75. Also, each student should be given a classification that reflects one of four interest groups: sport, music, nature, literature.
  2. +
+
#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 15
+#filter() can be used to set a maximum and minimum value
+#round() rounds numbers to whole number values
+#sample() draws a random samples from the groups vector according to a uniform distribution
+
+score <- rnorm(100, 75, 15)
+hist(score,breaks = 30)
+

+
S1 <- data.frame(score)
+
+library(dplyr)
+S1 <- filter(S1, score <= 100)
+hist(S1$score)
+

+
S2 <- data.frame(rep(100,100-nrow(S1)))
+names(S2) <- "score"
+S3 <- bind_rows(S1,S2)
+S3$score <- round(S3$score,0)
+interest <- c("sport","music","nature","literature")
+S3$interest <- sample(interest, 100, replace = TRUE)
+S3$stid <- seq(1,100,1)
+
    +
  1. Using base R commands, draw a histogram of the scores. Change the breaks in your histogram until you think they best represent your data.
  2. +
+
hist(S3$score, breaks = 10)
+

+
    +
  1. Create a new variable that groups the scores according to the breaks in your histogram.
  2. +
+
#cut() divides the range of scores into intervals and codes the values in scores according to which interval they fall. We use a vector called `letters` as the labels, `letters` is a vector made up of the letters of the alphabet.
+
+lable <- letters[1:10]
+S3$breaks <- cut(S3$score, breaks = 10, labels = lable)
+
    +
  1. Now using the colorbrewer package (RColorBrewer; http://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3) design a pallette and assign it to the groups in your data on the histogram.
  2. +
+
library(RColorBrewer)
+#Let's look at the available palettes in RColorBrewer
+display.brewer.all()
+

+
#The top section of palettes are sequential, the middle section are qualitative, and the lower section are diverging.
+#Make RColorBrewer palette available to R and assign to your bins
+S3$colors <- brewer.pal(10, "Spectral")
+#Use named palette in histogram
+hist(S3$score, col = S3$colors)
+

+
    +
  1. Create a boxplot that visualizes the scores for each interest group and color each interest group a different color.
  2. +
+
#Make a vector of the colors from RColorBrewer
+interest.col <- brewer.pal(4, "Dark2")
+
+boxplot(score ~ interest, S3, col = interest.col)
+

+
    +
  1. Now simulate a new variable that describes the number of logins that students made to the educational game. They should vary from 1-25.
  2. +
+
S3$logins <- sample(1:25, 100, replace = TRUE)
+
    +
  1. Plot the relationships between logins and scores. Give the plot a title and color the dots according to interest group.
  2. +
+
plot(S3$logins, S3$score, col = S3$colors, main = "Student Logins vs. Scores")
+

+
S3$col1 <- ifelse(S3$interest == "music", "red", "green")
+
    +
  1. R contains several inbuilt data sets, one of these in called AirPassengers. Plot a line graph of the the airline passengers over time using this data set.
  2. +
+
AP <- data.frame(AirPassengers)
+plot(AirPassengers)
+

+
    +
  1. Using another inbuilt data set, iris, plot the relationships between all of the variables in the data set. Which of these relationships is it appropraiet to run a correlation on?
  2. +
+
IRIS <- data.frame(iris)
+plot(iris)
+

+
#Petal.Length and Petal.Width is appropraiet to run a correlation.
+
+
+

Part III - Analyzing Swirl

+
+

Data

+

In this repository you will find data describing Swirl activity from the class so far this semester. Please connect RStudio to this repository.

+
+

Instructions

+
    +
  1. Insert a new code block

  2. +
  3. Create a data frame from the swirl-data.csv file called DF1

  4. +
+
DF1 <- read.csv("swirl-data.csv", header = TRUE)
+

The variables are:

+

course_name - the name of the R course the student attempted
+lesson_name - the lesson name
+question_number - the question number attempted correct - whether the question was answered correctly
+attempt - how many times the student attempted the question
+skipped - whether the student skipped the question
+datetime - the date and time the student attempted the question
+hash - anonymyzed student ID

+
    +
  1. Create a new data frame that only includes the variables hash, lesson_name and attempt called DF2
  2. +
+
DF2 <- select(DF1, hash, lesson_name, attempt)
+
    +
  1. Use the group_by function to create a data frame that sums all the attempts for each hash by each lesson_name called DF3
  2. +
+
DF3 <- DF2 %>% group_by(hash, lesson_name) %>% summarise(attempt = sum(attempt))
+
## `summarise()` regrouping output by 'hash' (override with `.groups` argument)
+
    +
  1. On a scrap piece of paper draw what you think DF3 would look like if all the lesson names were column names My Picture
  2. +
  3. Convert DF3 to this format
  4. +
+
DF3 <- spread(DF3, lesson_name, attempt)
+
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
+## Using compatibility `.name_repair`.
+## This warning is displayed once every 8 hours.
+## Call `lifecycle::last_warnings()` to see where this warning was generated.
+
    +
  1. Create a new data frame from DF1 called DF4 that only includes the variables hash, lesson_name and correct
  2. +
+
DF4 <- select(DF1, hash, lesson_name, correct)
+
    +
  1. Convert the correct variable so that TRUE is coded as the number 1 and FALSE is coded as 0
  2. +
+
DF4$correct <- ifelse(DF4$correct == TRUE, 1, 0)
+
    +
  1. Create a new data frame called DF5 that provides a mean score for each student on each course
  2. +
+
DF5 <- DF4 %>% group_by(hash, lesson_name) %>% summarise(mean.correct = mean(correct, na.rm = TRUE))
+
## `summarise()` regrouping output by 'hash' (override with `.groups` argument)
+
    +
  1. Extra credit Convert the datetime variable into month-day-year format and create a new data frame (DF6) that shows the average correct for each day
  2. +
+
DF1$datetime <- as.POSIXlt(DF1$datetime, origin = "1970-01-01")
+DF1$datetime <- strftime(DF1$datetime, format = "%m:%d")
+DF6 <- select(DF1, datetime, correct)
+DF6$correct <- ifelse(DF6$correct == TRUE, 1, 0)
+DF6 <- DF6 %>% group_by(datetime) %>% summarise(av.correct = mean(correct, na.rm = TRUE))
+
## `summarise()` ungrouping output (override with `.groups` argument)
+

Finally use the knitr function to generate an html document from your work. Commit, Push and Pull Request your work back to the main branch of the repository. Make sure you include both the .Rmd file and the .html file.

+
+
+
+ + + + +
+ + + + + + + + + + + + + + + From 481e8ad8bd7c67e3e77668cc8a968415ed1755c8 Mon Sep 17 00:00:00 2001 From: Stanley Zhao <70957528+ssz2119@users.noreply.github.com> Date: Tue, 15 Jun 2021 09:55:19 +0800 Subject: [PATCH 2/7] Update and rename Assignment 2-2020.Rmd to data manipulation.Rmd --- Assignment 2-2020.Rmd => data manipulation.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Assignment 2-2020.Rmd => data manipulation.Rmd (99%) diff --git a/Assignment 2-2020.Rmd b/data manipulation.Rmd similarity index 99% rename from Assignment 2-2020.Rmd rename to data manipulation.Rmd index 7fab49d..b0a27de 100644 --- a/Assignment 2-2020.Rmd +++ b/data manipulation.Rmd @@ -1,5 +1,5 @@ --- -title: "Assignment 2" +title: "Data Manipulation" author: "Stanley Zhao" date: "September 24, 2020" output: html_document From 766ab3130be025be2cd4cac9a68ecdd6217c7099 Mon Sep 17 00:00:00 2001 From: Stanley Zhao <70957528+ssz2119@users.noreply.github.com> Date: Tue, 15 Jun 2021 09:56:10 +0800 Subject: [PATCH 3/7] Delete Assignment-2-2020.html --- Assignment-2-2020.html | 643 ----------------------------------------- 1 file changed, 643 deletions(-) delete mode 100644 Assignment-2-2020.html diff --git a/Assignment-2-2020.html b/Assignment-2-2020.html deleted file mode 100644 index 65dff62..0000000 --- a/Assignment-2-2020.html +++ /dev/null @@ -1,643 +0,0 @@ - - - - - - - - - - - - - - - -Assignment 2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -

#Part I

-
-

Data Wrangling

-

In the hackathon a project was proposed to collect data from student video watching, a sample of this data is available in the file video-data.csv.

-

stid = student id year = year student watched video participation = whether or not the student opened the video watch.time = how long the student watched the video for confusion.points = how many times a student rewatched a section of a video key,points = how many times a student skipped or increased the speed of a video

-
#Install the 'tidyverse' package or if that does not work, install the 'dplyr' and 'tidyr' packages.
-
-#Load the package(s) you just installed
-
-library(tidyverse)
-
## ─ Attaching packages ─────────────────────────── tidyverse 1.3.0 ─
-
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
-## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
-## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
-## ✓ readr   1.3.1     ✓ forcats 0.5.0
-
## ─ Conflicts ──────────────────────────── tidyverse_conflicts() ─
-## x dplyr::filter() masks stats::filter()
-## x dplyr::lag()    masks stats::lag()
-
library(tidyr)
-library(dplyr)
-
-D1 <- read.csv("video-data.csv", header = TRUE)
-
-#Create a data frame that only contains the years 2018
-D2 <- filter(D1, year == 2018)
-
-
-

Histograms

-
#Generate a histogram of the watch time for the year 2018
-
-hist(D2$watch.time)
-

-
#Change the number of breaks to 100, do you get the same impression? No
-
-hist(D2$watch.time, breaks = 100)
-

-
#Cut the y-axis off at 10
-
-hist(D2$watch.time, breaks = 100, ylim = c(0,10))
-

-
#Restore the y-axis and change the breaks so that they are 0-5, 5-20, 20-25, 25-35
-
-hist(D2$watch.time, breaks = c(0,5,20,25,35))
-

-
-
-

Plots

-
#Plot the number of confusion points against the watch time
-
-plot(D1$confusion.points, D1$watch.time)
-

-
#Create two variables x & y
-x <- c(1,3,2,7,6,4,4)
-y <- c(2,4,2,3,2,4,3)
-
-#Create a table from x & y
-table1 <- table(x,y)
-
-#Display the table as a Barplot
-barplot(table1)
-

-
#Create a data frame of the average total key points for each year and plot the two against each other as a lines
-
-D3 <- D1 %>% group_by(year) %>% summarise(mean_key = mean(key.points))
-
## `summarise()` ungrouping output (override with `.groups` argument)
-
plot(D3$year, D3$mean_key, type = "l", lty = "dashed")
-

-
#Create a boxplot of total enrollment for three students
-D4 <- filter(D1, stid == 4|stid == 20| stid == 22)
-#The drop levels command will remove all the schools from the variable with no data  
-D4 <- droplevels(D4)
-boxplot(D4$watch.time~D4$stid, xlab = "Student", ylab = "Watch Time")
-

## Pairs

-
#Use matrix notation to select columns 2, 5, 6, and 7
-D5 <- D1[,c(2,5,6,7)]
-#Draw a matrix of plots for every combination of variables
-pairs(D5)
-

## Part II

-
    -
  1. Create a simulated data set containing 100 students, each with a score from 1-100 representing performance in an educational game. The scores should tend to cluster around 75. Also, each student should be given a classification that reflects one of four interest groups: sport, music, nature, literature.
  2. -
-
#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 15
-#filter() can be used to set a maximum and minimum value
-#round() rounds numbers to whole number values
-#sample() draws a random samples from the groups vector according to a uniform distribution
-
-score <- rnorm(100, 75, 15)
-hist(score,breaks = 30)
-

-
S1 <- data.frame(score)
-
-library(dplyr)
-S1 <- filter(S1, score <= 100)
-hist(S1$score)
-

-
S2 <- data.frame(rep(100,100-nrow(S1)))
-names(S2) <- "score"
-S3 <- bind_rows(S1,S2)
-S3$score <- round(S3$score,0)
-interest <- c("sport","music","nature","literature")
-S3$interest <- sample(interest, 100, replace = TRUE)
-S3$stid <- seq(1,100,1)
-
    -
  1. Using base R commands, draw a histogram of the scores. Change the breaks in your histogram until you think they best represent your data.
  2. -
-
hist(S3$score, breaks = 10)
-

-
    -
  1. Create a new variable that groups the scores according to the breaks in your histogram.
  2. -
-
#cut() divides the range of scores into intervals and codes the values in scores according to which interval they fall. We use a vector called `letters` as the labels, `letters` is a vector made up of the letters of the alphabet.
-
-lable <- letters[1:10]
-S3$breaks <- cut(S3$score, breaks = 10, labels = lable)
-
    -
  1. Now using the colorbrewer package (RColorBrewer; http://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3) design a pallette and assign it to the groups in your data on the histogram.
  2. -
-
library(RColorBrewer)
-#Let's look at the available palettes in RColorBrewer
-display.brewer.all()
-

-
#The top section of palettes are sequential, the middle section are qualitative, and the lower section are diverging.
-#Make RColorBrewer palette available to R and assign to your bins
-S3$colors <- brewer.pal(10, "Spectral")
-#Use named palette in histogram
-hist(S3$score, col = S3$colors)
-

-
    -
  1. Create a boxplot that visualizes the scores for each interest group and color each interest group a different color.
  2. -
-
#Make a vector of the colors from RColorBrewer
-interest.col <- brewer.pal(4, "Dark2")
-
-boxplot(score ~ interest, S3, col = interest.col)
-

-
    -
  1. Now simulate a new variable that describes the number of logins that students made to the educational game. They should vary from 1-25.
  2. -
-
S3$logins <- sample(1:25, 100, replace = TRUE)
-
    -
  1. Plot the relationships between logins and scores. Give the plot a title and color the dots according to interest group.
  2. -
-
plot(S3$logins, S3$score, col = S3$colors, main = "Student Logins vs. Scores")
-

-
S3$col1 <- ifelse(S3$interest == "music", "red", "green")
-
    -
  1. R contains several inbuilt data sets, one of these in called AirPassengers. Plot a line graph of the the airline passengers over time using this data set.
  2. -
-
AP <- data.frame(AirPassengers)
-plot(AirPassengers)
-

-
    -
  1. Using another inbuilt data set, iris, plot the relationships between all of the variables in the data set. Which of these relationships is it appropraiet to run a correlation on?
  2. -
-
IRIS <- data.frame(iris)
-plot(iris)
-

-
#Petal.Length and Petal.Width is appropraiet to run a correlation.
-
-
-

Part III - Analyzing Swirl

-
-

Data

-

In this repository you will find data describing Swirl activity from the class so far this semester. Please connect RStudio to this repository.

-
-

Instructions

-
    -
  1. Insert a new code block

  2. -
  3. Create a data frame from the swirl-data.csv file called DF1

  4. -
-
DF1 <- read.csv("swirl-data.csv", header = TRUE)
-

The variables are:

-

course_name - the name of the R course the student attempted
-lesson_name - the lesson name
-question_number - the question number attempted correct - whether the question was answered correctly
-attempt - how many times the student attempted the question
-skipped - whether the student skipped the question
-datetime - the date and time the student attempted the question
-hash - anonymyzed student ID

-
    -
  1. Create a new data frame that only includes the variables hash, lesson_name and attempt called DF2
  2. -
-
DF2 <- select(DF1, hash, lesson_name, attempt)
-
    -
  1. Use the group_by function to create a data frame that sums all the attempts for each hash by each lesson_name called DF3
  2. -
-
DF3 <- DF2 %>% group_by(hash, lesson_name) %>% summarise(attempt = sum(attempt))
-
## `summarise()` regrouping output by 'hash' (override with `.groups` argument)
-
    -
  1. On a scrap piece of paper draw what you think DF3 would look like if all the lesson names were column names My Picture
  2. -
  3. Convert DF3 to this format
  4. -
-
DF3 <- spread(DF3, lesson_name, attempt)
-
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
-## Using compatibility `.name_repair`.
-## This warning is displayed once every 8 hours.
-## Call `lifecycle::last_warnings()` to see where this warning was generated.
-
    -
  1. Create a new data frame from DF1 called DF4 that only includes the variables hash, lesson_name and correct
  2. -
-
DF4 <- select(DF1, hash, lesson_name, correct)
-
    -
  1. Convert the correct variable so that TRUE is coded as the number 1 and FALSE is coded as 0
  2. -
-
DF4$correct <- ifelse(DF4$correct == TRUE, 1, 0)
-
    -
  1. Create a new data frame called DF5 that provides a mean score for each student on each course
  2. -
-
DF5 <- DF4 %>% group_by(hash, lesson_name) %>% summarise(mean.correct = mean(correct, na.rm = TRUE))
-
## `summarise()` regrouping output by 'hash' (override with `.groups` argument)
-
    -
  1. Extra credit Convert the datetime variable into month-day-year format and create a new data frame (DF6) that shows the average correct for each day
  2. -
-
DF1$datetime <- as.POSIXlt(DF1$datetime, origin = "1970-01-01")
-DF1$datetime <- strftime(DF1$datetime, format = "%m:%d")
-DF6 <- select(DF1, datetime, correct)
-DF6$correct <- ifelse(DF6$correct == TRUE, 1, 0)
-DF6 <- DF6 %>% group_by(datetime) %>% summarise(av.correct = mean(correct, na.rm = TRUE))
-
## `summarise()` ungrouping output (override with `.groups` argument)
-

Finally use the knitr function to generate an html document from your work. Commit, Push and Pull Request your work back to the main branch of the repository. Make sure you include both the .Rmd file and the .html file.

-
-
-
- - - - -
- - - - - - - - - - - - - - - From 11c941e6707d4e267f8e2f4831c2880c8995bcf6 Mon Sep 17 00:00:00 2001 From: Stanley Zhao <70957528+ssz2119@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:22:35 +0800 Subject: [PATCH 4/7] Update README.md --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8ab360d..c1554a2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ -# Assignment 2 +# Data Manipulation Project ### Data Wrangling and Visualization -In Assignment 2 we will be practicing data manipulation including use of the tidyverse. +In this project, we will be practicing data manipulation including use of the tidyverse. -The instructions to Assignment 2 are in the Assignment 2-2020.rmd file. Assignments are structured in three parts, in the first part you can just follow along with the code, in the second part you will need to apply the code, and in the third part is completely freestyle and you are expected to apply your new knowledge in a new way. +The final work are in the data manipulation.rmd file. The work is divided in to three different parts based on its structure. In the first part there are examples to show you how to construct the code, which you may follow along with the code to have an idea of it. In the second part you will need to apply what you learned in the first part, and answer the respective questions. In the last part you are completely free of how you answer the questions. It could be what you learned in the first part, or it could also be knowledges from outside research. -**Please complete as much as you can by midnight EDT, 10/05/20** - -Once you have finished, commit, push and pull your assignment back to the main branch. Include both the .Rmd file and the .html file. +Once it is finished, commit, push and pull the data manipulation project back to the main branch. Good luck! From 63ab521763a010936d57676b61588683e5422219 Mon Sep 17 00:00:00 2001 From: Stanley Zhao <70957528+ssz2119@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:23:02 +0800 Subject: [PATCH 5/7] Update swirl-data.csv --- swirl-data.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swirl-data.csv b/swirl-data.csv index 66d19c9..fb6dbd3 100644 --- a/swirl-data.csv +++ b/swirl-data.csv @@ -21,7 +21,7 @@ "R Programming","Dates and Times",24,"TRUE",1,FALSE,1505668172.17721,30802 "R Programming","Subsetting Vectors",27,"TRUE",1,FALSE,1505505439.02967,30802 "R Programming","Dates and Times",23,"TRUE",1,FALSE,1505668154.23643,30802 -"R Programming","Dates and Times",19,"TRUE",1,FALSE,1505668109.32478,30802 +"R Programming","Dates and Times",19,"TRUE",1,FALSE,1505668109.32478,30802 "R Programming","Subsetting Vectors",22,"TRUE",1,FALSE,1505505353.49589,30802 "R Programming","Functions",5,"TRUE",1,FALSE,1505668637.37404,30802 "R Programming","Subsetting Vectors",26,"TRUE",1,FALSE,1505505409.78315,30802 From 8a9897cdadf8d4513103ec877616540e46c2a31f Mon Sep 17 00:00:00 2001 From: Stanley Zhao <70957528+ssz2119@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:23:18 +0800 Subject: [PATCH 6/7] Update video-data.csv --- video-data.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video-data.csv b/video-data.csv index 5fcb3ef..3bb3dbf 100644 --- a/video-data.csv +++ b/video-data.csv @@ -296,6 +296,6 @@ 55,2019,"E",1,13.5,9,2 56,2019,"E",1,12,6,2 57,2019,"E",1,17.5,10,1 -58,2019,"E",1,6,4,1 +58,2019,"E",1,6,4,1 59,2019,"E",0,0,0,0 60,2019,"E",0,0,0,0 From 67a0da814b1d176b399318823cfd840ac06290b5 Mon Sep 17 00:00:00 2001 From: Stanley Zhao <70957528+ssz2119@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:23:37 +0800 Subject: [PATCH 7/7] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5b6a065..f0bdebb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .Rhistory .RData .Ruserdata +