QUESTION IMAGE
Question
you are given a data set in the file finance.csv with the following column names: year, month, revenues, costs, and profits. your manager asked you to find the number of rows such that the costs< profits. which of the following statement(s) could you use?
- for loop with if else statement
ii. for loop with ifelse function
iii. while loop with if else statement
iv. repeat loop with ifelse function
i, iii and iv
i, ii, iii and iv
ii and iv
i and iii
Step1: Analyze for loop with if else statement
A for loop can iterate over the rows of the data - set. The if else statement can be used to check the condition \( Costs < Profits \). So, this combination is valid.
Step2: Analyze for loop with ifelse function
In many programming languages, the ifelse function is a vectorized operation. A for loop is an iterative construct. Mixing a for loop (iterative) with an ifelse (vectorized in some languages like R) in the context of row - by - row checking (assuming a non - vectorized data - access in a loop) is not a standard or correct approach for row - by - row condition checking in a loop.
Step3: Analyze while loop with if else statement
A while loop can also be used to iterate over the rows (by maintaining an index variable). The if else statement can check the \( Costs < Profits \) condition. So, this combination is valid.
Step4: Analyze repeat loop with ifelse function
The repeat loop is a loop that repeats until a break condition is met. Similar to the for loop - ifelse combination, using an ifelse (vectorized in some languages) with a repeat loop (iterative) for row - by - row condition checking in a loop is not a standard or correct approach.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
I and III