0
0
R Programmingprogramming~15 mins

Ifelse vectorized function in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the ifelse Vectorized Function in R
📖 Scenario: You are working with a list of students' scores. You want to quickly label each score as "Pass" or "Fail" based on a passing mark.
🎯 Goal: Create a vector of scores, set a passing threshold, use the ifelse function to label each score as "Pass" or "Fail", and print the result.
📋 What You'll Learn
Create a numeric vector called scores with the values 45, 67, 89, 34, 56
Create a numeric variable called pass_mark and set it to 50
Use the ifelse function with scores and pass_mark to create a character vector called results labeling scores as "Pass" or "Fail"
Print the results vector
💡 Why This Matters
🌍 Real World
Teachers and trainers often need to quickly classify student scores to identify who passed or failed.
💼 Career
Data analysts and statisticians use vectorized functions like <code>ifelse</code> in R to efficiently process and categorize data.
Progress0 / 4 steps
1
Create the scores vector
Create a numeric vector called scores with these exact values: 45, 67, 89, 34, 56
R Programming
Need a hint?

Use the c() function to combine numbers into a vector.

2
Set the passing mark
Create a numeric variable called pass_mark and set it to 50
R Programming
Need a hint?

Assign the number 50 to the variable pass_mark using the assignment operator <-.

3
Use ifelse to label pass or fail
Use the ifelse function with scores and pass_mark to create a character vector called results that contains "Pass" if the score is greater than or equal to pass_mark, otherwise "Fail"
R Programming
Need a hint?

The ifelse function takes three arguments: a condition, a value if true, and a value if false.

4
Print the results vector
Print the results vector using the print() function
R Programming
Need a hint?

Use print(results) to show the vector on the screen.