DO THIS IN R: (I need the code for making this new vaible) (I have a data set th
ID: 3219369 • Letter: D
Question
DO THIS IN R: (I need the code for making this new vaible)
(I have a data set that has a varible grade in it and i need to make a new variable GradeNew from subsets of this varible as follows)
Create a simpler variable GradeNew. GradeNew should equal $A$ if the students grade was an $A+, A,$ or $A-$. GradeNew should equal $B$ if the students grade was an $B+, B,$ or $B-$. GradeNew should equal $C$ if the students grade was an $C+, C,$ or $C-$. Finally, GradeNew should equal $Other$ if the students grade was an $D+, D, D-, F, I, S,$ or $W$.
Explanation / Answer
R Code:
GradeNew <- ifelse((Grade == "A+")|(Grade == "A")|(Grade == "A-"), "A",
ifelse((Grade == "B+")|(Grade == "B")|(Grade == "B-"), "B",
ifelse((Grade == "C+")|(Grade == "C")|(Grade == "C-"), "C","Other")))
The usage of ifelse is ifelse(test, yes, no). If the condition is not satisfied, I have used further ifelse to create nested ifelse.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.