Question

Use R or R studio to complete the following Do NOT use the function “rank()” or...

Use R or R studio to complete the following

Do NOT use the function “rank()” or “order()” from base R,

1) rank the scores in “MidtermGradeSheet.csv” by using a function from package “tidyverse” and make sure who got the highest score would receive rank “1” (5pts);

Student ID Midterm
AE 81
AN 78.5
AS 82
CA 94
CF 77
DN 87
DR 99.5
EA 74
EC 75.5
EE 70.5
EI 79
EL 96.5
EP 81.5
ET 65.5
EU 93
HM 87.5
IA 89.5
AA 83.5
LA 90.5
LM 77
LW 86
MA 86
OA 81.5
OI 75
OO 70
QA 72.5
RA 93.5
RN 90
SA 92.5
TA 86
TN 81
UO 90
VJ 68
XD 61
YB 89
YC 72
YE 92

2) and then add a new column to the original table with the name “new_rank” showing the ranks (3pts).

3) Save it as a csv file with the name as “ranked_midterm_scores_again” (1.5pt). Tell me where it was saved to (in which folder I can find it). (0.5pt) Type down all the R codes and results.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the solution below. Let me know if you have any doubt.

setwd('E:\\projects\\work\\HomeworkLib\\R\\rank')
dataframe<-read.csv('MidtermGradeSheet.csv',header = T, sep = ",")

#1
df<-arrange(dataframe, desc(Midterm)) %>%
mutate(rank = 1:nrow(dataframe))

#2
dataframe<-merge(dataframe,df,by =c('Student.ID','Midterm'),all.x = T)

#3
write.csv(x = dataframe,file = 'ranked_midterm_scores_again.csv',row.names = FALSE)

Output:


Add a comment
Know the answer?
Add Answer to:
Use R or R studio to complete the following Do NOT use the function “rank()” or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT