I have a list of the grades of my students from several courses. I want to select the 1st quartile (saving in a group with the name A) and the 3rd quartile (saving in a group with the name B) and the rest of the students saving in a group with the name C. My question is how can I save their grades in that separate group? and how can I find the students in each quartile?
I used summary to see quartiles
Mark=SS(summary)
HIS BIO CHE
Min. :-6.800 Min. :-23.30 Min. :-25.20
1st Qu.: 1.500 1st Qu.: 12.10 1st Qu.: 17.70
Median : 2.200 Median : 16.70 Median : 23.90
Mean : 2.126 Mean : 16.71 Mean : 23.91
3rd Qu.: 3.800 3rd Qu.: 22.40 3rd Qu.: 31.10
Max. :20.200 Max. : 67.30 Max. : 77.20
quantile(SS$HIS, 0.25)
1.500
Kind regards
CodePudding user response:
One option is use the quantile()
function to obtain the values of the quartiles and then use the cut()
function to define the groups.
#create test data
x <- as.integer(runif(50, 0, 100))
#find the bottom 25% and top 25% grades (and min & max)
qunats <- quantile(x, c(0, .25, .75, 1))
qunats
#now cut the data into section
grade <- cut(x, qunats, include.lowest = TRUE, labels=c("C", "B", "A"))
data.frame(x, grade)