Conditional Operators Building a condition in R

Viewed 153

I need to build a condition if all the numbers in the vector marks (passed as arguments) are greater than 110. If yes, assign the string "top" to the variable M, else assign "Down"

I try making this but it´s doesnt marks me as correct

classmark<-function(marks){


    V1 <- marks > 110
    V<- ifelse(V1 == TRUE,"Best Class","Needs Improvement")
    
    return(V)
    }
    print(classmark(c(120,195,914,56)))
    print(classmark(c(130,295,294,196)))

This is the original code

    classmark<-function(marks){
    
        # Enter your code here. Read input from STDIN. Print output to STDOUT
        V<-
        
        return(V)
        }
    print(classmark(c(120,195,914,56)))
    print(classmark(c(130,295,294,196)))
1 Answers
classmark <- function(marks) {
    if (all(marks > 110)) {
        "top"
    } else {
        "Down"
    }
}
M <- classmark(c(120,195,914,56))
M
#> [1] "Down"
M <- classmark(c(130,295,294,196))
M
#> [1] "top"
Related