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, 56Create a numeric variable called
pass_mark and set it to 50Use 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