Complete the code to use ifelse to assign 'pass' if score is 50 or more, else 'fail'.
result <- ifelse(score [1] 50, 'pass', 'fail')
The ifelse function checks if score is greater than or equal to 50 to assign 'pass'.
Complete the code to assign 'even' if number is divisible by 2, else 'odd'.
result <- ifelse(number %% 2 [1] 0, 'even', 'odd')
The modulo operator %% returns 0 for even numbers, so we check if it equals 0.
Fix the error in the ifelse condition to correctly assign 'adult' if age is 18 or more.
category <- ifelse(age [1] 18, 'adult', 'minor')
Adults are those with age greater than or equal to 18, so '>=' is correct.
Fill both blanks to create a vectorized ifelse that labels numbers as 'positive' if greater than zero, else 'non-positive'.
labels <- ifelse(numbers [1] 0, 'positive', [2])
The condition checks if numbers are greater than zero for 'positive', else assigns 'non-positive'.
Fill all three blanks to create a vectorized ifelse that labels temperatures as 'hot' if above 30, 'cold' if below 15, else 'warm'.
labels <- ifelse(temp [1] 30, 'hot', ifelse(temp [2] 15, 'cold', [3]))
The first condition checks if temp is greater than 30 for 'hot'. The nested ifelse checks if temp is less than 15 for 'cold'. Otherwise, it assigns 'warm'.