Question
Using R, Please write a user define function quiz_fct to display student quiz scores comments based on students score. The function quiz_fct will display comments
Using R, Please write a user define function quiz_fct to display student quiz scores comments based on students score. The function quiz_fct will display comments based on a students quiz scores.
(1) First, you are required to load data from quiz.csv in R to create a data frame and name it quiz_df.
Got this: quiz_df<-read.table("source of file", header = TRUE, sep=",")
When creating function quiz_fct, you need to use a loop and multi-if-elseif-else control constructs inside the function even_fct to complete your task.
Comments rules if students quiz score match following status:
Quiz < 60 # display comment Failed
Quiz >= 60 and Quiz < 70 # display comment Poor
Quiz >= 70 and Quiz < 80 # display comment Average
Quiz >= 80 and Quiz < 90 # display comment Good
Quiz >= 90 # display comment Great
> quiz_fct <- function(x){
comment<-c() # create an empty vector and name it comment
length <- nrow(x) # number of rows inside the data frame quiz_df
# your codes
# your codes
x<- data.frame(x,comment)
return(x) }
> y <- quiz_fct(quiz_df)
> y
name quiz1 comment
1 Jack 80 Good
2 John 70 Average
3 Jennifer 90 Great
4 Joe 60 Poor
5 Judy 50 Failed
6 Jay 90 Great
7 July 100 Great
8 Jason 100 Great
9 Jill 100 Great
quiz.csv includes:
name | quiz1 |
Jack | 80 |
John | 70 |
Jennifer | 90 |
Joe | 60 |
Judy | 50 |
Jay | 90 |
July | 100 |
Jason | 100 |
Jill | 100 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started