0
0
R Programmingprogramming~15 mins

Logical operators (&, |, !, &&, ||) in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Logical Operators in R
📖 Scenario: You are working with a small dataset of students' test scores. You want to find out which students passed based on certain conditions using logical operators.
🎯 Goal: Build a simple R program that uses logical operators &, |, and ! to check students' scores and print who passed.
📋 What You'll Learn
Create a named vector called scores with exact student names and scores
Create a variable called pass_mark with the value 60
Use logical operators &, |, and ! to find students who passed or failed
Print the final result showing which students passed
💡 Why This Matters
🌍 Real World
Logical operators help filter and select data based on conditions, useful in data analysis and decision making.
💼 Career
Understanding logical operators is essential for data scientists, analysts, and programmers to write conditions and control program flow.
Progress0 / 4 steps
1
Create the scores vector
Create a named numeric vector called scores with these exact entries: Alice = 58, Bob = 75, Charlie = 62, Diana = 45, Eva = 80.
R Programming
Need a hint?

Use the c() function with named elements like Alice = 58.

2
Set the passing mark
Create a variable called pass_mark and set it to the number 60.
R Programming
Need a hint?

Just assign the number 60 to pass_mark.

3
Use logical operators to find who passed
Create a logical vector called passed that is TRUE for students with scores greater than or equal to pass_mark and FALSE otherwise. Use the logical operator >=.
R Programming
Need a hint?

Use passed <- scores >= pass_mark to get TRUE or FALSE for each student.

4
Print the students who passed
Use print() to display the names of students who passed. Use the logical vector passed to select names from scores.
R Programming
Need a hint?

Use names(scores)[passed] inside print() to show who passed.