Recap - Grade Classifier
Part of the Logic & Flow section of Coddy's R journey. Lesson 51 of 64.
Challenge
MediumComplete grade_report(names, scores). Give each student a grade with ifelse(): A from 90, B from 75, C from 50 and F below 50. Return one line per student, ada: 93 (A) Excellent, where the comment comes from a switch() on the grade: Excellent for A, Good for B, Pass for C and Retake for F.
Then add Top: followed by the students with the highest score, in input order and joined with , .
The supplied code reads the names and the scores as two comma-separated lines and prints each returned line.
Try it yourself
grade_report <- function(names, scores) {
# Write your code here
character(0)
}
# Supplied input/output code: keep it as it is
input <- suppressWarnings(readLines(file("stdin")))
cat(grade_report(strsplit(input[1], ",")[[1]], as.numeric(strsplit(input[2], ",")[[1]])), sep = "\n")
All lessons in Logic & Flow
1Strings In Depth
Substrings with substr()Formatting with sprintf()Splitting and JoiningSearching StringsReplacing TextRecap - Username Builder4Matrices
Creating MatricesIndexing MatricesRow and Column SummariesMatrix ArithmeticRecap - Seating Chart10Advanced Control Flow
The switch() FunctionVectorized ifelse()repeat and breakRecursive FunctionsRecap - Grade Classifier2Key-Value Lookups
Named Vector LookupsChecking KeysAdding and Removing KeysLooping Over NamesRecap - Stock Desk3Sets and Counting
Unique ValuesSet OperationsMembership TestsCounting with table()Recap - Event Guests6Functions as Values
Anonymous FunctionsPassing FunctionsReturning FunctionsClosures with StateRecap - Discount Rules9Data Frames
Creating Data FramesColumns and RowsFiltering RowsAdding and SortingRecap - Sales Report12Project - Expense Tracker
Recording ExpensesTotal SpendingPractice on your own: Online R compiler