Load libraries

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

Create the dataframe of scores for various assignments in the course

Grades<-data.frame(Student_ID=c("Student1","Student2", "Student3","Student4", "Student5"),
CA1=c(80,100,"-",95,100),
CA2=c(90,100,95,90,82),
CA3=c("-",100,90,100,100),
Assignment=c(95,97,92,80,75),
Midterm_Project=c(98,100,95,93,90),
Final_Project=c(95,92,95,100,90))

head(Grades)
##   Student_ID CA1 CA2 CA3 Assignment Midterm_Project Final_Project
## 1   Student1  80  90   -         95              98            95
## 2   Student2 100 100 100         97             100            92
## 3   Student3   -  95  90         92              95            95
## 4   Student4  95  90 100         80              93           100
## 5   Student5 100  82 100         75              90            90

Replace CA1 score for Student3 with 0 (Student3 did not turn in anything for class activity). Also, overwrite and convert CA1 to numeric.

Grades$CA1 <- as.numeric(replace(Grades$CA1, Grades$CA1 == "-", 0))

Replace CA3 score for Student1 with 85 and convert CA3 to numeric.

Grades$CA3 <- as.numeric(replace(Grades$CA3, Grades$CA3 == "-", 85))

Save the changes in new dataframe named Grades2

Grades2 <- Grades
head(Grades2)
##   Student_ID CA1 CA2 CA3 Assignment Midterm_Project Final_Project
## 1   Student1  80  90  85         95              98            95
## 2   Student2 100 100 100         97             100            92
## 3   Student3   0  95  90         92              95            95
## 4   Student4  95  90 100         80              93           100
## 5   Student5 100  82 100         75              90            90

Add a new column to Grades2 dataframe that computes the average class activity scores for each student and save the resulting dataframe as Grades3.

Grades3 <- Grades2 %>% mutate(CA_Average = (CA1 + CA2 + CA3)/3)
head(Grades3)
##   Student_ID CA1 CA2 CA3 Assignment Midterm_Project Final_Project CA_Average
## 1   Student1  80  90  85         95              98            95   85.00000
## 2   Student2 100 100 100         97             100            92  100.00000
## 3   Student3   0  95  90         92              95            95   61.66667
## 4   Student4  95  90 100         80              93           100   95.00000
## 5   Student5 100  82 100         75              90            90   94.00000

Add a new column to Grades3 dataframe that computes the weighted average for each student and save the resulting dataframe as Grades4 using the grading weights in the course syllabus.

[Hint: weighted average can be calculated as: CA_Average ∗0.3+ Assignment ∗0.15+ Midterm_Project ∗0.25+ Final_Project ∗0.3.

Grades4 <- Grades3 %>% mutate(Weighted_Average = CA_Average * 0.3 + Assignment * 0.15 + Midterm_Project * 0.25 + Final_Project * 0.3)
head(Grades4)
##   Student_ID CA1 CA2 CA3 Assignment Midterm_Project Final_Project CA_Average
## 1   Student1  80  90  85         95              98            95   85.00000
## 2   Student2 100 100 100         97             100            92  100.00000
## 3   Student3   0  95  90         92              95            95   61.66667
## 4   Student4  95  90 100         80              93           100   95.00000
## 5   Student5 100  82 100         75              90            90   94.00000
##   Weighted_Average
## 1            92.75
## 2            97.15
## 3            84.55
## 4            93.75
## 5            88.95