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.

Instructions associated with this assignment can be found in the file “InstructionsPlayingwithData.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, 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.

Set working directory (replace with your actual directory path)

setwd(“/path/to/your/working/directory”)

Load required packages

library(openxlsx) library(dplyr) library(tidyverse)

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.

Load the Excel file

grade_book <- read.xlsx(“Assignment5_GradeBook.xlsx”, sheet = “Sheet1”) attendance <- read.xlsx(“Assignment5_GradeBook.xlsx”, sheet = “Sheet2”)

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.

Display first 15 rows of grade book

head(grade_book, 15)

Display first 15 rows of attendance

head(attendance, 15)

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.

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.

In the grade book data set, rename the variables so that they do not have a . in their names.

After renaming the variables, look at the first 15 observations for each data set.

Rename attendance variables

attendance <- attendance %>% rename( meeting1 = 1, meeting2 = 2, meeting3 = 3, meeting4 = 4, meeting5 = 5 )

Rename grade book variables (remove periods)

grade_book <- grade_book %>% rename( Midterm1 = Midterm 1, Midterm2 = Midterm 2, Assignment1 = Assignment 1, Assignment2 = Assignment 2, Assignment3 = Assignment 3, Final = Final )

Check the first 15 observations after renaming

head(grade_book, 15) head(attendance, 15)

6. Creating New Attendance Variables

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

After you have completed these calculations, take a look at the first 15 observations in your data set.

Calculate total classes attended

attendance <- attendance %>% mutate( Total_Attended = meeting1 + meeting2 + meeting3 + meeting4 + meeting5, Total_Absent = 5 - Total_Attended, Total_Unexcused_Absences = pmax(Total_Absent - 2, 0), # Allowed 2 excused absences Penalty = Total_Unexcused_Absences * 0.5 )

Check the first 15 observations

head(attendance, 15)

7. Create New Grade Variables

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

There are multiple ways one can calculate the overall grade for the class. You are going to calculate the final grade in two different ways.

  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).

  2. 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.

After you have completed these calucations, take a look at the first 15 observations in your data set.

Convert raw scores to percentages

grade_book <- grade_book %>% mutate( Assignment1_Percent = (Assignment1 / 10) * 100, Assignment2_Percent = (Assignment2 / 10) * 100, Assignment3_Percent = (Assignment3 / 10) * 100, Midterm1_Percent = (Midterm1 / 20) * 100, Midterm2_Percent = (Midterm2 / 20) * 100, Final_Percent = (Final / 30) * 100 )

Calculate final grade (equal weight)

grade_book <- grade_book %>% mutate( Final_Grade_Equal_Weight = (Assignment1_Percent + Assignment2_Percent + Assignment3_Percent + Midterm1_Percent + Midterm2_Percent + Final_Percent) / 6 )

Calculate final grade (weighted by original points)

grade_book <- grade_book %>% mutate( Final_Grade_Weighted = (Assignment1 + Assignment2 + Assignment3 + Midterm1 + Midterm2 + Final) / 100 )

Check the first 15 observations

head(grade_book, 15)

8. Create Objects Containing a Single Value

In this section, insert chunks and calculate mean, minimum, and maximum for 3 different variables (midterm 2, assignment 3, and the final exam) in the grade book data set. Use the variables that report the scores as a percent that you created.

Calculate mean, min, and max for Midterm2_Percent

midterm2_mean <- mean(grade_book\(Midterm2_Percent, na.rm = TRUE) midterm2_min <- min(grade_book\)Midterm2_Percent, na.rm = TRUE) midterm2_max <- max(grade_book$Midterm2_Percent, na.rm = TRUE)

Calculate mean, min, and max for Assignment3_Percent

assignment3_mean <- mean(grade_book\(Assignment3_Percent, na.rm = TRUE) assignment3_min <- min(grade_book\)Assignment3_Percent, na.rm = TRUE) assignment3_max <- max(grade_book$Assignment3_Percent, na.rm = TRUE)

Calculate mean, min, and max for Final_Percent

final_mean <- mean(grade_book\(Final_Percent, na.rm = TRUE) final_min <- min(grade_book\)Final_Percent, na.rm = TRUE) final_max <- max(grade_book$Final_Percent, na.rm = TRUE)

9. Create Objects Containing Multiple Values

In this section, insert chunks and produce the following objects that will contain values for each variable in the data set.

Attendance summary

attendance_summary <- attendance %>% summarise( Total_Students = n(), Mean_Attendance = mean(Total_Attended) )

Grade book summary

grade_summary <- grade_book %>% summarise(across(ends_with(“Percent”), list(mean = mean, min = min, max = max))

10. Combining Objects

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

Combine attendance summary objects

attendance_combined <- c(attendance_summary\(Total_Students, attendance_summary\)Mean_Attendance)

Combine grade book summary objects

grade_combined <- c(grade_summary\(Midterm2_Percent_mean, grade_summary\)Midterm2_Percent_min, grade_summary\(Midterm2_Percent_max, grade_summary\)Assignment3_Percent_mean, grade_summary\(Assignment3_Percent_min, grade_summary\)Assignment3_Percent_max, grade_summary\(Final_Percent_mean, grade_summary\)Final_Percent_min, grade_summary$Final_Percent_max)

11. Export Data Sets

In this section, insert a chunk of code to export the grade book data, the attendance data, the summary grade book, and the summary attendance as one Excel file. Make sure to name your data file something different than the Excel file that had the original data that you loaded into R for this assignment.

Create a list of data frames to export

data_list <- list( Grade_Book = grade_book, Attendance = attendance, Grade_Summary = grade_summary, Attendance_Summary = attendance_summary )

Export to Excel

write.xlsx(data_list, “Final_GradeBook_Summary.xlsx”)

12. Did you recieve help?

No one helped me

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

No help provided

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.