From 0b6c3d55e767694b8888daccd420f5573a11d1ca Mon Sep 17 00:00:00 2001 From: XYR Date: Tue, 6 Oct 2020 10:23:39 +0800 Subject: [PATCH] assignment 2 --- Assignment 2-2020.Rmd | 108 +++- Assignment-2-2020.html | 1061 ++++++++++++++++++++++++++++++++++++++++ README.md | 8 +- assignment2.Rproj | 13 + 4 files changed, 1178 insertions(+), 12 deletions(-) create mode 100644 Assignment-2-2020.html create mode 100644 assignment2.Rproj diff --git a/Assignment 2-2020.Rmd b/Assignment 2-2020.Rmd index 081fcec..9a231cc 100644 --- a/Assignment 2-2020.Rmd +++ b/Assignment 2-2020.Rmd @@ -92,16 +92,37 @@ pairs(D5) ```{r} #rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 20 -#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 +#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) + +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= T) + +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,xlim = c(40,100),ylim = c(0,20)) + ``` @@ -110,6 +131,9 @@ 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. +label <- letters[1:10] +S3$breaks <- cut(S3$score, breaks = 10, labels = label) + ``` @@ -118,12 +142,14 @@ 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 - +#brewer.pal(n, name) +#n:Number of different colors in the palette, minimum 3, maximum depending on #palette +S3$colors <- brewer.pal(10,"Set3") #Use named palette in histogram - +hist(S3$score, col = S3$colors) ``` @@ -131,13 +157,15 @@ library(RColorBrewer) ```{r} #Make a vector of the colors from RColorBrewer - +interest.col <- brewer.pal(4,"Dark2") +boxplot(S3$score~S3$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$login <- sample(c(1:25),100,replace= T) ``` @@ -145,13 +173,17 @@ library(RColorBrewer) ```{r} - +S3$col1 <- ifelse(S3$interest == "music", "red", ifelse(S3$interest == "literature","green", ifelse(S3$interest == "sport","blue","yellow"))) +plot(S3$login, S3$score, type = "p",col=S3$col1, main ="Student Logins vs.Scores") ``` 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} +AirPassengers +plot(AirPassengers, type = "l") + ``` @@ -159,6 +191,7 @@ library(RColorBrewer) 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} +plot(iris) ``` @@ -171,7 +204,17 @@ 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 +228,68 @@ 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 <- DF1 %>% select(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 = sum(attempt ,na.rm = T)) + +``` + 5. On a scrap piece of paper draw what you think `DF3` would look like if all the lesson names were column names +```{r} + +unique_lesson_name <- unique(DF3 $lesson_name) +unique_lesson_name +``` + 6. Convert `DF3` to this format +```{r} +library(reshape2) +DF31 <- DF3 +dcast(DF31,DF31$hash ~ DF31$lesson_name) +DF31 <- na.omit(DF31) +DF3 <- DF31 +``` + 7. Create a new data frame from `DF1` called `DF4` that only includes the variables `hash`, `lesson_name` and `correct` +```{r} +DF4 <- DF1 %>% select(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} + +boolean <- ifelse(DF4$correct == "TRUE", 1, 0) +DF4$correct <- boolean + +``` + 9. Create a new data frame called `DF5` that provides a mean score for each student on each course +```{r} +#`hash`, `lesson_name` and `correct` +DF5 <- DF4 %>% group_by(hash, lesson_name) %>% summarise(mean_correct = mean(correct ,na.rm = T)) +DF5 <- na.omit(DF5) + +``` + 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} +POSIXct_date <- as.POSIXct(DF1$datetime, origin="1970-01-01",tz="Pacific/Auckland") +POSIXct_date <- as.Date(POSIXct_date,"%m/%d/%Y",tz="Pacific/Auckland") +``` + 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..372bca1 --- /dev/null +++ b/Assignment-2-2020.html @@ -0,0 +1,1061 @@ + + + + + + + + + + + + + + + +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?
+
+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 20
+#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)
+
+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= T)
+
+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,xlim = c(40,100),ylim = c(0,20))
+

+
    +
  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.
+label <- letters[1:10]
+S3$breaks <- cut(S3$score, breaks = 10, labels = label)
+
    +
  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
+#brewer.pal(n, name)
+#n:Number of different colors in the palette, minimum 3, maximum depending on #palette
+S3$colors <- brewer.pal(10,"Set3")
+#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(S3$score~S3$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$login <- sample(c(1:25),100,replace= T)
+
    +
  1. Plot the relationships between logins and scores. Give the plot a title and color the dots according to interest group.
  2. +
+
S3$col1 <- ifelse(S3$interest == "music", "red", ifelse(S3$interest == "literature","green", ifelse(S3$interest == "sport","blue","yellow")))
+plot(S3$login, S3$score, type = "p",col=S3$col1, main ="Student Logins vs.Scores")
+

+
    +
  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. +
+
AirPassengers
+
##      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
+## 1949 112 118 132 129 121 135 148 148 136 119 104 118
+## 1950 115 126 141 135 125 149 170 170 158 133 114 140
+## 1951 145 150 178 163 172 178 199 199 184 162 146 166
+## 1952 171 180 193 181 183 218 230 242 209 191 172 194
+## 1953 196 196 236 235 229 243 264 272 237 211 180 201
+## 1954 204 188 235 227 234 264 302 293 259 229 203 229
+## 1955 242 233 267 269 270 315 364 347 312 274 237 278
+## 1956 284 277 317 313 318 374 413 405 355 306 271 306
+## 1957 315 301 356 348 355 422 465 467 404 347 305 336
+## 1958 340 318 362 348 363 435 491 505 404 359 310 337
+## 1959 360 342 406 396 420 472 548 559 463 407 362 405
+## 1960 417 391 419 461 472 535 622 606 508 461 390 432
+
plot(AirPassengers, type = "l")
+

+
    +
  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. +
+
plot(iris)
+

+
+
+

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 <- DF1 %>% select(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 = sum(attempt ,na.rm = T))
+
## `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
  2. +
+
unique_lesson_name <- unique(DF3 $lesson_name)
+unique_lesson_name
+
##  [1] "Basic Building Blocks"            "Dates and Times"                 
+##  [3] "Logic"                            "Matrices and Data Frames"        
+##  [5] "Missing Values"                   "Subsetting Vectors"              
+##  [7] "Vectors"                          "Workspace and Files"             
+##  [9] ""                                 "Grouping and C"                  
+## [11] "Grouping and Chaining with dplyr" "Lo"                              
+## [13] "Looking at Data"                  "Manipulating Data with dplyr"    
+## [15] "Subsetti"                         "Tidying Data with tid"           
+## [17] "Tidying Data with tidyr"          "Functions"                       
+## [19] "Base_Plotting_System"             "Clustering_Example"              
+## [21] "Exploratory_Graphs"               "Graphics_Devices_in_R"           
+## [23] "Grouping and Chaining w"          "Hierarchica"                     
+## [25] "Hierarchical_Clustering"          "K_Means_Clustering"              
+## [27] "Looking"                          "Principles_of_Analytic_Graphs"   
+## [29] "Tidying Data "                    "Plotting_Systems"                
+## [31] "Manipulatin"                      "Fu"
+
    +
  1. Convert DF3 to this format
  2. +
+
library(reshape2)
+
## 
+## Attaching package: 'reshape2'
+
## The following object is masked from 'package:tidyr':
+## 
+##     smiths
+
DF31 <- DF3
+dcast(DF31,DF31$hash ~ DF31$lesson_name)
+
## Using attempt_sum as value column: use value.var to override.
+
##    DF31$hash Var.2 Base_Plotting_System Basic Building Blocks
+## 1       2864    NA                   NA                    29
+## 2       4807    NA                   NA                    49
+## 3       6487    NA                   NA                    25
+## 4       8766    NA                   NA                    NA
+## 5      11801     0                   NA                    16
+## 6      12264    NA                   NA                    NA
+## 7      14748    NA                   NA                    29
+## 8      16365     0                   NA                    17
+## 9      20682     0                   NA                    NA
+## 10     21536     0                   19                    NA
+## 11     24042    NA                   NA                    39
+## 12     27264    NA                   55                    NA
+## 13     27286     0                   NA                    NA
+## 14     27487    NA                   NA                    29
+## 15     30802    NA                   NA                    25
+## 16     32870    NA                   NA                    16
+## 17     34068    NA                   NA                    23
+## 18     34362    NA                   NA                    23
+## 19     35235    NA                   NA                    29
+## 20     44419     0                   NA                    31
+## 21     45253     0                   NA                    NA
+## 22     46250    NA                   NA                    29
+## 23     55259    NA                   NA                    NA
+## 24     64610    NA                   NA                    25
+## 25     65259     0                   NA                    NA
+## 26     67994    NA                   NA                    NA
+## 27     68515    NA                   NA                    27
+## 28     70464    NA                   NA                    25
+## 29     74372    NA                   NA                    25
+## 30     75323    NA                   NA                    NA
+## 31     75332     0                   NA                    15
+## 32     76966    NA                   NA                    NA
+## 33     77484    NA                   NA                    NA
+## 34     78719    NA                   NA                    37
+## 35     80970    NA                   NA                    NA
+## 36     86730     0                   NA                    NA
+## 37     88135    NA                   NA                    36
+## 38     92108    NA                   NA                    23
+## 39     94880    NA                   NA                    25
+## 40     96746    NA                   NA                    23
+## 41     98193     0                   NA                    NA
+##    Clustering_Example Dates and Times Exploratory_Graphs Fu Functions
+## 1                  NA              NA                 NA NA        NA
+## 2                  NA              51                 NA NA        NA
+## 3                  NA              NA                 NA NA        NA
+## 4                  NA              NA                 NA NA        NA
+## 5                  NA              18                 NA NA        NA
+## 6                  NA              NA                 NA NA        79
+## 7                  NA              31                 NA NA       165
+## 8                  NA              19                 NA NA        41
+## 9                  NA              NA                 NA NA        NA
+## 10                 14              NA                 14 NA        NA
+## 11                 NA              42                 NA NA       130
+## 12                 54              29                 NA NA        54
+## 13                 NA              NA                 NA NA        NA
+## 14                 NA              40                 NA NA        NA
+## 15                 NA              29                 NA NA        40
+## 16                 NA              NA                 NA NA        NA
+## 17                 NA              NA                 NA NA        NA
+## 18                 NA              37                 NA NA       115
+## 19                 NA              NA                 NA NA        NA
+## 20                 NA              17                 NA NA        64
+## 21                 NA              NA                 NA NA        NA
+## 22                 NA              37                 NA NA        38
+## 23                 NA              NA                 NA NA        NA
+## 24                 NA              NA                 NA NA        NA
+## 25                 NA              19                 NA NA        NA
+## 26                 NA              NA                 NA NA        NA
+## 27                 NA              33                 NA NA       251
+## 28                 NA              85                 NA NA        41
+## 29                 NA              NA                 NA NA        NA
+## 30                 NA              NA                 NA  0        19
+## 31                 NA              18                 NA NA        NA
+## 32                 NA              NA                 NA NA        NA
+## 33                 NA              NA                 NA NA        NA
+## 34                 NA              35                 NA NA        44
+## 35                 NA              35                 NA NA        35
+## 36                 NA              NA                 NA NA        NA
+## 37                 NA              NA                 NA NA        NA
+## 38                 NA              35                 NA NA        NA
+## 39                 NA              45                 NA NA        58
+## 40                 NA              NA                 NA NA        NA
+## 41                 NA              NA                 NA NA        NA
+##    Graphics_Devices_in_R Grouping and C Grouping and Chaining w
+## 1                     NA             NA                      NA
+## 2                     NA             NA                      NA
+## 3                     NA             NA                      NA
+## 4                     NA             NA                      NA
+## 5                     NA              0                      NA
+## 6                     NA             NA                      NA
+## 7                     NA             NA                      NA
+## 8                     NA             NA                      NA
+## 9                     NA             NA                      NA
+## 10                    14             NA                       0
+## 11                    NA             NA                      NA
+## 12                    NA             NA                      NA
+## 13                    NA             NA                      NA
+## 14                    NA             NA                      NA
+## 15                    NA             NA                      NA
+## 16                    NA             NA                      NA
+## 17                    NA             NA                      NA
+## 18                    NA             NA                      NA
+## 19                    NA             NA                      NA
+## 20                    NA             NA                      NA
+## 21                    NA             NA                      NA
+## 22                    NA             NA                      NA
+## 23                    NA             NA                      NA
+## 24                    NA             NA                      NA
+## 25                    NA             NA                      NA
+## 26                    NA             NA                      NA
+## 27                    NA             NA                      NA
+## 28                    NA             NA                      NA
+## 29                    NA             NA                      NA
+## 30                    NA             NA                      NA
+## 31                    NA             NA                      NA
+## 32                    NA             NA                      NA
+## 33                    NA             NA                      NA
+## 34                    NA             NA                      NA
+## 35                    NA             NA                      NA
+## 36                    NA             NA                      NA
+## 37                    NA             NA                      NA
+## 38                    NA             NA                      NA
+## 39                    NA             NA                      NA
+## 40                    NA             NA                      NA
+## 41                    NA             NA                      NA
+##    Grouping and Chaining with dplyr Hierarchica Hierarchical_Clustering
+## 1                                NA          NA                      NA
+## 2                                NA          NA                      NA
+## 3                                NA          NA                      NA
+## 4                                NA          NA                      NA
+## 5                                12          NA                      NA
+## 6                                NA          NA                      NA
+## 7                                NA          NA                      NA
+## 8                                NA          NA                      NA
+## 9                                NA          NA                      NA
+## 10                               13           0                      22
+## 11                               NA          NA                      NA
+## 12                               41          NA                      NA
+## 13                               NA          NA                      NA
+## 14                               NA          NA                      NA
+## 15                               NA          NA                      NA
+## 16                               NA          NA                      NA
+## 17                               NA          NA                      NA
+## 18                               NA          NA                      NA
+## 19                               NA          NA                      NA
+## 20                               NA          NA                      NA
+## 21                               NA          NA                      NA
+## 22                               NA          NA                      NA
+## 23                               NA          NA                      NA
+## 24                               NA          NA                      NA
+## 25                               NA          NA                      NA
+## 26                               NA          NA                      NA
+## 27                               NA          NA                      NA
+## 28                               NA          NA                      NA
+## 29                               NA          NA                      NA
+## 30                               NA          NA                      NA
+## 31                               NA          NA                      NA
+## 32                               NA          NA                      NA
+## 33                               36          NA                      NA
+## 34                               38          NA                      NA
+## 35                               49          NA                      NA
+## 36                               NA          NA                      NA
+## 37                               NA          NA                      NA
+## 38                               NA          NA                      NA
+## 39                               NA          NA                      NA
+## 40                               NA          NA                      NA
+## 41                               NA          NA                      NA
+##    K_Means_Clustering Lo Logic Looking Looking at Data Manipulatin
+## 1                  NA NA    NA      NA              NA          NA
+## 2                  NA NA   116      NA              NA          NA
+## 3                  NA NA    NA      NA              NA          NA
+## 4                  NA NA    NA      NA              NA          NA
+## 5                  NA  0    20      NA              18          NA
+## 6                  NA NA    NA      NA              NA          NA
+## 7                  NA NA    62      NA              NA          NA
+## 8                  NA NA    20      NA              NA          NA
+## 9                  NA NA    NA      NA              NA          NA
+## 10                 24 NA    NA       0              15          NA
+## 11                 NA NA    36      NA              NA          NA
+## 12                 NA NA    36      NA              20          NA
+## 13                 NA NA    NA      NA              NA          NA
+## 14                 NA NA    56      NA              NA          NA
+## 15                 NA NA    42      NA              NA          NA
+## 16                 NA NA    NA      NA              NA          NA
+## 17                 NA NA    NA      NA              NA          NA
+## 18                 NA NA    52      NA              NA          NA
+## 19                 NA NA    NA      NA              NA          NA
+## 20                 NA NA    24      NA              NA          NA
+## 21                 NA NA    NA      NA              NA          NA
+## 22                 NA NA    52      NA              NA          NA
+## 23                 NA NA    NA      NA              NA          NA
+## 24                 NA NA    NA      NA              NA          NA
+## 25                 NA NA    NA      NA              NA           0
+## 26                 NA NA    NA      NA              NA          NA
+## 27                 NA NA    68      NA              NA          NA
+## 28                 NA NA    54      NA              NA          NA
+## 29                 NA NA    NA      NA              NA          NA
+## 30                 NA NA    NA      NA              NA          NA
+## 31                 NA NA    19      NA              NA          NA
+## 32                 NA NA    NA      NA              NA          NA
+## 33                 NA NA    NA      NA              21          NA
+## 34                 NA NA    45      NA              16          NA
+## 35                 NA NA    47      NA              18          NA
+## 36                 NA NA    NA      NA              NA          NA
+## 37                 NA NA    NA      NA              NA          NA
+## 38                 NA NA    45      NA              NA          NA
+## 39                 NA NA    38      NA              NA          NA
+## 40                 NA NA    NA      NA              NA          NA
+## 41                 NA NA    NA      NA              NA          NA
+##    Manipulating Data with dplyr Matrices and Data Frames Missing Values
+## 1                            NA                       NA             NA
+## 2                            NA                       43             19
+## 3                            NA                       NA             NA
+## 4                            NA                       NA             20
+## 5                            13                       17             17
+## 6                            67                       35             NA
+## 7                            NA                       NA             15
+## 8                            NA                       33             19
+## 9                            NA                       NA             NA
+## 10                           19                       NA             NA
+## 11                           NA                       NA             17
+## 12                           48                       28             15
+## 13                           NA                       NA             NA
+## 14                           NA                       30             20
+## 15                           NA                       NA             15
+## 16                           NA                       NA             NA
+## 17                           NA                       NA             NA
+## 18                           NA                       NA             15
+## 19                           NA                       NA             NA
+## 20                           NA                       16             15
+## 21                           NA                       NA             NA
+## 22                           NA                       NA             17
+## 23                           NA                       NA             NA
+## 24                           NA                       NA             NA
+## 25                           13                       NA             NA
+## 26                           NA                       37             NA
+## 27                           NA                       NA             15
+## 28                           NA                       NA             26
+## 29                           NA                       NA             17
+## 30                           NA                       NA             NA
+## 31                           NA                       NA             15
+## 32                           NA                       38             NA
+## 33                           55                       31             NA
+## 34                           47                       52             21
+## 35                           57                       NA             22
+## 36                           NA                       NA             NA
+## 37                           NA                       NA             NA
+## 38                           NA                       NA             21
+## 39                           NA                       NA             19
+## 40                           NA                       61             NA
+## 41                           NA                       NA             NA
+##    Plotting_Systems Principles_of_Analytic_Graphs Subsetti Subsetting Vectors
+## 1                NA                            NA       NA                 NA
+## 2                NA                            NA       NA                 35
+## 3                NA                            NA       NA                 NA
+## 4                NA                            NA       NA                 NA
+## 5                NA                            NA        0                 16
+## 6                NA                            NA       NA                 NA
+## 7                NA                            NA       NA                119
+## 8                NA                            NA       NA                 17
+## 9                NA                            NA       NA                 NA
+## 10               NA                            14       NA                 NA
+## 11               NA                            NA       NA                 35
+## 12               26                            NA       NA                 31
+## 13               NA                            NA       NA                 NA
+## 14               NA                            NA       NA                 31
+## 15               NA                            NA       NA                 27
+## 16               NA                            NA       NA                 NA
+## 17               NA                            NA       NA                 NA
+## 18               NA                            NA       NA                 44
+## 19               NA                            NA       NA                 NA
+## 20               NA                            NA       NA                 25
+## 21               NA                            NA       NA                 NA
+## 22               NA                            NA       NA                 50
+## 23               NA                            NA       NA                 NA
+## 24               NA                            NA       NA                 NA
+## 25               NA                            NA       NA                 NA
+## 26               NA                            NA       NA                 NA
+## 27               NA                            NA       NA                 51
+## 28               NA                            NA       NA                 45
+## 29               NA                            NA       NA                 NA
+## 30               NA                            NA       NA                 NA
+## 31               NA                            NA       NA                 17
+## 32               NA                            NA       NA                 NA
+## 33               28                            NA       NA                 NA
+## 34               28                            NA       NA                 31
+## 35               46                            NA       NA                 34
+## 36               NA                            NA       NA                 NA
+## 37               NA                            NA       NA                 NA
+## 38               NA                            NA       NA                 36
+## 39               NA                            NA       NA                 31
+## 40               NA                            NA       NA                 NA
+## 41               NA                            NA       NA                 NA
+##    Tidying Data  Tidying Data with tid Tidying Data with tidyr Vectors
+## 1             NA                    NA                      NA      NA
+## 2             NA                    NA                      NA      35
+## 3             NA                    NA                      NA      NA
+## 4             NA                    NA                      NA      28
+## 5             NA                     0                      23      20
+## 6             NA                    NA                      91      NA
+## 7             NA                    NA                      NA      24
+## 8             NA                    NA                      NA      24
+## 9             NA                    NA                      NA      NA
+## 10             0                    NA                      15      NA
+## 11            NA                    NA                      NA      29
+## 12            NA                    NA                      NA      26
+## 13            NA                    NA                      NA      NA
+## 14            NA                    NA                      NA      26
+## 15            NA                    NA                      NA      24
+## 16            NA                    NA                      NA      NA
+## 17            NA                    NA                      NA      NA
+## 18            NA                    NA                      NA      44
+## 19            NA                    NA                      NA      NA
+## 20            NA                    NA                      NA      39
+## 21            NA                    NA                      NA      NA
+## 22            NA                    NA                      NA      52
+## 23            NA                    NA                      NA      NA
+## 24            NA                    NA                      NA      NA
+## 25            NA                    NA                      NA      NA
+## 26            NA                    NA                      NA      NA
+## 27            NA                    NA                      NA      26
+## 28            NA                    NA                      NA      24
+## 29            NA                    NA                      NA      42
+## 30            NA                    NA                      NA      NA
+## 31            NA                    NA                      NA      20
+## 32            NA                    NA                      NA      NA
+## 33            NA                    NA                      94      NA
+## 34            NA                    NA                     122      24
+## 35            NA                    NA                      77      43
+## 36            NA                    NA                      NA      NA
+## 37            NA                    NA                      NA      NA
+## 38            NA                    NA                      NA      26
+## 39            NA                    NA                      NA      20
+## 40            NA                    NA                      NA      NA
+## 41            NA                    NA                      NA      NA
+##    Workspace and Files
+## 1                   NA
+## 2                   39
+## 3                   NA
+## 4                   39
+## 5                   16
+## 6                   NA
+## 7                   30
+## 8                   19
+## 9                   NA
+## 10                  NA
+## 11                  32
+## 12                  NA
+## 13                  NA
+## 14                  NA
+## 15                  26
+## 16                  NA
+## 17                  NA
+## 18                  71
+## 19                  NA
+## 20                  18
+## 21                  NA
+## 22                  37
+## 23                  32
+## 24                  NA
+## 25                  NA
+## 26                  NA
+## 27                  38
+## 28                  35
+## 29                  32
+## 30                  NA
+## 31                  21
+## 32                  NA
+## 33                  NA
+## 34                  26
+## 35                  43
+## 36                  NA
+## 37                  NA
+## 38                  32
+## 39                  34
+## 40                  NA
+## 41                  NA
+
DF31 <- na.omit(DF31)
+DF3 <- DF31
+
    +
  1. Create a new data frame from DF1 called DF4 that only includes the variables hash, lesson_name and correct
  2. +
+
DF4 <- DF1 %>% select(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. +
+
boolean <- ifelse(DF4$correct == "TRUE", 1, 0) 
+DF4$correct <- boolean
+
    +
  1. Create a new data frame called DF5 that provides a mean score for each student on each course
  2. +
+
#`hash`, `lesson_name` and `correct`
+DF5 <- DF4 %>% group_by(hash, lesson_name) %>% summarise(mean_correct = mean(correct ,na.rm = T))
+
## `summarise()` regrouping output by 'hash' (override with `.groups` argument)
+
DF5 <- na.omit(DF5)
+
    +
  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. +
+
POSIXct_date <- as.POSIXct(DF1$datetime, origin="1970-01-01",tz="Pacific/Auckland")
+POSIXct_date <- as.Date(POSIXct_date,"%m/%d/%Y",tz="Pacific/Auckland")
+

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/README.md b/README.md index 747ccba..8ab360d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Assignment 2 ### Data Wrangling and Visualization -In Assignment 2 we will be looking at some interaction data from students commenting on a class video. The file "comment-data.csv" shows which student responded to which student in an online video platform. +In Assignment 2 we will be practicing data manipulation including use of the tidyverse. -The instructions to Assignment 2 are in the Assignment 2.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, apply your new knowledge in a new way. +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. -**Please complete as much as you can by 5:00pm, 10/05/20** +**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 the .Rmd file and the .html file generated from your .Rmd file. +Once you have finished, commit, push and pull your assignment back to the main branch. Include both the .Rmd file and the .html file. Good luck! diff --git a/assignment2.Rproj b/assignment2.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/assignment2.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX