Comparing total winnings in R | Calculation using vector | Question 4

R Programming Language / Vector in R Language

471

Program:

# Poker and roulette winnings from Monday to Friday:
poker_vector <- c(140, -50, 20, -120, 240)
roulette_vector <- c(-24, -50, 100, -350, 10)
days_vector <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
names(poker_vector) <- days_vector
names(roulette_vector) <- days_vector

# Calculate total gains for poker and roulette
total_poker <- sum(poker_vector)
total_roulette <- sum(roulette_vector)

# Check if you realized higher total gains in poker than in roulette 
total_poker > total_roulette

Output:

> # Poker and roulette winnings from Monday to Friday:
> poker_vector <- c(140, -50, 20, -120, 240)
> roulette_vector <- c(-24, -50, 100, -350, 10)
> days_vector <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
> names(poker_vector) <- days_vector
> names(roulette_vector) <- days_vector
> 
> # Calculate total gains for poker and roulette
> total_poker <- sum(poker_vector)
> total_roulette <- sum(roulette_vector)
> 
> # Check if you realized higher total gains in poker than in roulette 
> total_poker > total_roulette
[1] TRUE

Explanation:

Hint
  • You partly calculated the answer to this question in the previous exercise already!
  • To check if 6 is larger than 5, you type 6 > 5. This returns a logical value (TRUE or FALSE).

This Particular section is dedicated to Programs only. If you want learn more about R Programming Language. Then you can visit below links to get more depth on this subject.