tpemartin / 110-1-r4ds-main

MIT License
3 stars 73 forks source link

Exercise 4.8 A school adopt letter grade system from C to A+ as follows: #36

Open tpemartin opened 2 years ago

tpemartin commented 2 years ago

A school adopt letter grade system from C to A+ as follows:

letter_grades <- c("C", "B-", "B", "B+", "A-", "A", "A+")

However, when there is need to calulate GPA, they convert each letter grade to each value in the following numeric_grades vector:

numeric_grades <- c(2, 2.5, 3, 3.5, 4, 4.5, 5)

A student with the following letter grades need to convert them to numeric_grades:

studentGrades <- c('B','A','A+','B+','A-','B','B-','B','A+','B+','C','B-','B-','B','C','C','B+','B','B+','B')

He asked you for help. You layout the following programming plan:

studentLetterGrades <- {
  # Task map c("C", "B-", "B", "B+", "A-", "A", "A+") to c(2, 2.5, 3, 3.5, 4, 4.5, 5)

  # step1: for each grade in studentGrades find its position in c("C", "B-", "B", "B+", "A-", "A", "A+") so if studentGrades = c("C","A-"), step1 = c(1, 5) since c("C", "B-", "B", "B+", "A-", "A", "A+")[c(1, 5)] will give him "C", "A-"

  # step2: Use step1 result as position indices to retrieve from c(2, 2.5, 3, 3.5, 4, 4.5, 5). From previous example, step1=c(1, 5), then  c(2, 2.5, 3, 3.5, 4, 4.5, 5)[step1] will give him c(2, 4)

}

Complete the programming block.

raychiu135 commented 2 years ago

https://github.com/raychiu135/110-1-r4ds-main/blob/52519c461799d4e40fb2fbc983d207bd713cc5e3/exercise_4.8.rmd#L2

Vincent23412 commented 2 years ago

https://github.com/Vincent23412/110-1-r4ds-main/blob/bd83d77d595817955b932658bc688552edf029f2/20211127.Rmd#L42

AmyChen20021003 commented 2 years ago

teacher, can you explain this exercise next week?

Jimmy885 commented 2 years ago

https://github.com/Jimmy885/110-1-r4ds-main/blob/c578bea448139461967067a4f75b1950c2b4d28e/4.8.rmd#L635

linttttt commented 2 years ago

https://github.com/linttttt/110-1-r4ds-main/blob/a7e32a7334911a1117cad0cde2aed838ed825bb4/studyCH4(EX).Rmd#L43