I have a data frame df that has a column indicating the grade level of each participant in that data frame. Grade levels range from "K" to "9". I have another table called "quantile" that contains the cut-off values of each quantile of the test score for each grade level. How can I create a new column in the df data which indicates the quantile of each students' test score based on the reference table "quantile"? The rule is that if a test score's value is less than the value of the cut-off, that test score belongs to the quantile of the cut-off value. And, if the test score is between 2 cut-off values, that test score is classified as the greater quantile. Thank you much!
Below is the dummy data and the result table I was looking for:
df <- data.frame("Name" = c("John", "Mary", "Emily"), "Grade" = c("8","9","10"), "Test Score" = c(5,61,60))
df
quantile <- data.frame("Grade" = c("8","9","10"), "Quantile 1" = c(10,15,20), "Quantile 2" = c(50,60,70),
"Quantile 3" = c(60,80,100))
quantile
result <- data.frame("Name" = c("John", "Mary", "Emily"), "Grade" = c("8","9","10"),"Test Score" = c(5,61,60),
"Quantile" = c("Quantile 1","Quantile 3","Quantile 2") )
result