id name major gender grade course 1 101 Bill CIS M 92 CIS240 2 102 Mary CIS F 88
ID: 3726033 • Letter: I
Question
id name major gender grade course
1 101 Bill CIS M 92 CIS240
2 102 Mary CIS F 88 CIS240
3 103 Sue Marketing F 82 MKT115
4 104 Tom Finance M 78 DBA120
5 105 Alex CIS M 96 CIS240
6 106 Sam Marketing M 67 MKT115
7 107 Jane Finance F 95 DBA120
Let’s make the above data more descriptive. Nobody knows what CIS240, MKT115, and DBA120 are. You need to add a course description to each row of the above. Your output should look like the following. Your output should look like the following.
id name major gender grade course updateGrade description
1 101 Bill CIS M 92 CIS240 95 Intro to Computer Sci
2 102 Mary CIS F 88 CIS240 91 Intro to Computer Sci
3 103 Sue Marketing F 82 MKT115 85 Marketing Skills
4 104 Tom Finance M 78 DBA120 81 Oracle in Finance
5 105 Alex CIS M 96 CIS240 99 Intro to Computer Sci
6 106 Sam Marketing M 67 MKT115 70 Marketing Skills
7 107 Jane Finance F 95 DBA120 98 Oracle in Finance
What is the command statement to achieve the goal?
[Answer:]
Please create a new data frame student_sort based on the student data frame. You need to write down R codes to rank students’ updateGrade in a descending order (from the lowest exam grade to the highest exam grade). Your output should look like the following.
id name major gender grade course updateGrade description
6 106 Sam Marketing M 67 MKT115 70 Marketing Skills
4 104 Tom Finance M 78 DBA120 81 Oracle in Finance
3 103 Sue Marketing F 82 MKT115 85 Marketing Skills
2 102 Mary CIS F 88 CIS240 91 Intro to Computer Sci
1 101 Bill CIS M 92 CIS240 95 Intro to Computer Sci
7 107 Jane Finance F 95 DBA120 98 Oracle in Finance
5 105 Alex CIS M 96 CIS240 99 Intro to Computer Sci
[Answer:]
Now, please write down R codes to calculate the male students’ average exam of upgradeGrade and the average exam of upgradeGrade for female students.
Your output should look like the following.
[1] 91.33333
[1] 86.25
Explanation / Answer
>id=c(101:107)
> name=c("Bill","Mary","sue","Tom","Alex","Sam","Jane")
> major=c("CIS","CIS","Marketing","Finance","CIS","Marketing","Finance")
> gender=c("M","F","F","M","M","M","F")
> grade=c(92,88,82,78,96,67,95)
> student=data.frame(id,name,major,gender,grade,course)
>description=c("Intro to Computer Sci","Marketing Skills","Oracle in Finance")
> subject_code=c("CIS240","MKT115","DBA120")
> subject_info=data.frame(subject_code,description)
> student=merge(student,subject_info,by.x="course",by.y = "subject_code", all.x=TRUE)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.