Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert percentage to letter grade in R

Tags:

r

I have created an R script to calculate final scores for a class I am teaching, and would like to use R to create the final letter grade. How can I take a vector of percentages such as:

grades <- c(.47, .93, .87, .86, .79, .90)

and convert them to letter grades given the appropriate percentage ranges, say, 70-79 = C, 80-89 = B, 90-100 = A?

like image 420
Ryan Avatar asked Mar 18 '23 16:03

Ryan


1 Answers

grades <- c(.47, .93, .87, .86, .79, .90)
letter.grade <- cut(grades, c(0, 0.7,0.8,0.9,Inf), right=FALSE, labels=letters[4:1]);
letter.grade

As @MrFlick suggested you can use cut. The right = FALSE options means that the interval is not inclusive on the right hand end. For cut to work just pass your grades and the cut points you want as the argument.

Thanks to @jlhoward for the improvement suggestion

like image 122
xiaodai Avatar answered Mar 20 '23 05:03

xiaodai