Overview

This file contains a set of tasks that you need to complete in R for the lab assignment. The tasks may require you to add a code chuck, type code into a chunk, and/or execute code. Some tasks may also ask you to answer specific questions. Don’t forget that you need to acknowledge if you used any resources beyond class materials or got help to complete the assignment.

Additional information and examples relevant to this assignment can be found in the file “PlayingWithDataTutorial.html”.

The data set you will use is different than the one used in the instructions. Pay attention to the differences in the Excel files name, any variable names, and/or object names. You will need to adjust your code accordingly.

Once you have completed the assignment, you will need to knit this R Markdown file to produce an html file. You will then need to upload the .html file and this .Rmd file to AsULearn. Additionally, for this assignment you will upload the Excel file you created.

1. Add your name and the date

The first thing you need to do in this file is to add your name and date in the lines underneath this document’s title (see the code in lines 10 and 11).

2. Getting started

Insert a chunk of code in this section to identify and set your working directory and load packages. We will use the same three packages we did in the last lab: openxlsx, dplyr and tidyverse.
setwd(“/Users/corddoss/Desktop/Research methods class/”) library(dplyr) Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

filter, lag

The following objects are masked from ‘package:base’:

intersect, setdiff, setequal, union
 library(tidyverse)

── Attaching core tidyverse packages ─────────── ✔ forcats 1.0.1 ✔ readr 2.1.5 ✔ ggplot2 4.0.0 ✔ stringr 1.5.2 ✔ lubridate 1.9.4 ✔ tibble 3.3.0 ✔ purrr 1.1.0 ✔ tidyr 1.3.1 ── Conflicts ────────── tidyverse_conflicts() ── ✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag() ℹ Use the conflicted package to force all conflicts to become errors library(openxlsx) # 3. Load Two Data Sets Insert a chunk of code in this section to load your data. The Excel file for this assignment has two sheets: grades and attendance. Sheet 1 contains the grades data and Sheet 2 contains the attendance data. You will want to load each sheet into R as separate data objects. The name of the Excel file is different than what is in the instructions. Accordingly, you will need to adjust the code to read in the Excel file that was downloaded as part of the zip file. GradeBook <- read.xlsx(“GradeBook.xlsx” , sheet = 1) > head(GradeBook, 10) X1 Midterm.1 Midterm.2 Assignment.1 1 Noah 15.00000 12.00000 5.000000 2 Jack 11.00478 15.00000 6.771172 3 Emily 20.00000 20.00000 8.000000 4 Colin 20.00000 17.00000 8.000000 5 Hannah 10.00000 17.00000 6.802136 6 Aubrie 20.00000 14.00000 5.000000 7 Olivia 14.00000 17.72971 10.000000 8 Duncan 9.62783 16.00000 7.000000 9 Katie 19.00000 12.00000 9.000000 10 Jackson 17.00000 15.00000 8.000000 Assignment.2 Assignment.3 Final 1 8.000000 5.661442 30.00000 2 10.000000 8.000000 26.00000 3 8.000000 8.154995 20.00000 4 5.000000 8.673615 25.00000 5 9.604730 10.000000 20.00000 6 6.000000 6.000000 17.78453 7 7.000000 6.000000 26.00000 8 8.065708 8.000000 18.95910 9 8.000000 8.967217 20.00000 10 6.000000 2.549882 25.00000 Attendance <- read.xlsx(“GradeBook.xlsx” , sheet = 2) > head(Attendance, 10) Name 1 2 3 4 5 1 Noah 1 1 1 1 1 2 Jack 0 1 1 1 1 3 Emily 1 1 0 0 1 4 Colin 1 0 1 1 1 5 Hannah 1 1 0 1 1 6 Aubrie 1 1 1 1 1 7 Olivia 1 1 1 1 1 8 Duncan 0 1 0 0 1 9 Katie 1 1 1 1 1 10 Jackson 1 0 1 1 1 # 4. Take a look at your data Insert a chunk of code in this section and display the first 15 observations of each data set. head(Attendance, 15) Name 1 2 3 4 5 1 Noah 1 1 1 1 1 2 Jack 0 1 1 1 1 3 Emily 1 1 0 0 1 4 Colin 1 0 1 1 1 5 Hannah 1 1 0 1 1 6 Aubrie 1 1 1 1 1 7 Olivia 1 1 1 1 1 8 Duncan 0 1 0 0 1 9 Katie 1 1 1 1 1 10 Jackson 1 0 1 1 1 11 Victoria 1 1 1 1 1 12 Matthew 1 1 0 1 0 13 Michael 0 1 1 1 1 14 Olivia 1 1 1 1 1 15 Samantha 1 0 1 1 1 # 5. Rename Variables You will need to insert chunks of code and rename variables in your data sets in this section. I recommend trying to do only one thing per chunk of code. Attendance %>% + rename(Class1 = “1”, + Class2 = “2”, + Class3 = “3”, + Class4 = “4”, + Class5 = “5”) -> Attendance In the attendance data set, you will need to rename the variables that are currently numbers into text. In the instructions, I called each variable Class and then the number of that class, for example Class1. Instead of using the same variable name as I did, you should call each variable a Meeting. Attendance %>% + rename(Meeting1 = “Class1”, + Meeting2 = “Class2”, + Meeting3 = “Class3”, + Meeting4 = “Class4”, + Meeting5 = “Class5”) -> Attendance head(Attendance, 15) Name Meeting1 Meeting2 Meeting3 Meeting4 1 Noah 1 1 1 1 2 Jack 0 1 1 1 3 Emily 1 1 0 0 4 Colin 1 0 1 1 5 Hannah 1 1 0 1 6 Aubrie 1 1 1 1 7 Olivia 1 1 1 1 8 Duncan 0 1 0 0 9 Katie 1 1 1 1 10 Jackson 1 0 1 1 11 Victoria 1 1 1 1 12 Matthew 1 1 0 1 13 Michael 0 1 1 1 14 Olivia 1 1 1 1 15 Samantha 1 0 1 1 Meeting5 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 0 13 1 14 1 15 1 In the grade book data set, rename the variables so that they do not have a . in their names. GradeBook %>% + rename(Name = “X1”, + Midterm1 = “Midterm.1”, + Midterm2 = “Midterm.2”, + Assignment1 = “Assignment.1”, + Assignment2 = “Assignment.2”, + Assignment3 = “Assignment.3”, + Final = “Final”) -> GradeBook After renaming the variables, look at the first 15 observations for each data set. head(GradeBook, 15) Name Midterm1 Midterm2 Assignment1 1 Noah 15.00000 12.00000 5.000000 2 Jack 11.00478 15.00000 6.771172 3 Emily 20.00000 20.00000 8.000000 4 Colin 20.00000 17.00000 8.000000 5 Hannah 10.00000 17.00000 6.802136 6 Aubrie 20.00000 14.00000 5.000000 7 Olivia 14.00000 17.72971 10.000000 8 Duncan 9.62783 16.00000 7.000000 9 Katie 19.00000 12.00000 9.000000 10 Jackson 17.00000 15.00000 8.000000 11 Victoria 11.00000 9.93236 8.000000 12 Matthew 10.00000 13.00000 10.000000 13 Michael 7.00000 11.00000 8.000000 14 Olivia 14.00000 12.00000 6.000000 15 Samantha 6.00000 10.00000 6.000000 Assignment2 Assignment3 Final 1 8.000000 5.661442 30.00000 2 10.000000 8.000000 26.00000 3 8.000000 8.154995 20.00000 4 5.000000 8.673615 25.00000 5 9.604730 10.000000 20.00000 6 6.000000 6.000000 17.78453 7 7.000000 6.000000 26.00000 8 8.065708 8.000000 18.95910 9 8.000000 8.967217 20.00000 10 6.000000 2.549882 25.00000 11 10.000000 6.701154 26.00000 12 9.000000 10.000000 26.00000 13 10.000000 10.000000 18.00000 14 7.000000 8.000000 29.00000 15 8.000000 6.000000 19.00000 # 6. Creating New Attendance Variables In this section, insert chunks and create the following variables in your attendance data set. Attendance %>% + mutate(Present = (Meeting1 + Meeting2 + Meeting3 + Meeting4 + Meeting5)) -> Attendance - Total number of classes attended.

7. Create New Grade Variables

In this section, insert chunks and create the following variables in your grade book data set.

  1. You should provide equal weight to each item in the class regardless of the number of points it was originally worth. To do this, you should add together the percentage grades that you calculated and divide by 600 (you have 6 assignments, each one is worth up to 100 points once the grades were converted to percents). GradeBook %>%
  1. You should weight items based on the number of points each was originally worth. The most straightforward way to do this is to add together the raw scores for each item and then divide by the total number of points possible. You already have the information you need to calculate the total number of points possible because you know how many points each type of assignment is worth and you know how many of each type of assignment is in the grade book.
    GradeBook %>%

10. Combining Objects

In this section, insert chunks of code that will combine objects together.

13. Did you provide anyone help with completing this lab?

Enter the names of anyone that you assisted with completing this lab. If you did not help anyone, then just type out that you didn’t help anyone. no # 14. Knit the Document Click the “Knit” button to publish your work as an html document. This document or file will appear in the folder specified by your working directory. You will need to upload both this RMarkdown file and the html file it produces to AsU Learn to get all of the lab points for this week. Additionally, you need to upload the Excel file that you exported when completing the assignment to get all of the lab points for this week.