Advanced selection

Just like you did for poker, you also want to know those days where you realized a positive return for roulette.

Instruction

# 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 # Which days did you make money on roulette? selection_vector <- # Select from roulette_vector these days roulette_winning_days <- # 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 # Which days did you make money on roulette? selection_vector <- roulette_vector > 0 # Select from roulette_vector these days roulette_winning_days <- roulette_vector[selection_vector] msg = "Do not change anything about the definition and naming of `poker_vector` and `roulette_vector`." test_object("days_vector", undefined_msg = msg, incorrect_msg = msg) test_object("poker_vector", eq_condition = "equal", undefined_msg = msg, incorrect_msg = msg) test_object("roulette_vector", eq_condition = "equal", undefined_msg = msg, incorrect_msg = msg) test_object("selection_vector", incorrect_msg = "It looks like `selection_vector` does not contain the correct result. Use `roulette_vector > 0`.") test_object("roulette_winning_days", incorrect_msg = "It looks like `roulette_winning_days` does not contain the correct result. Use `roulette_vector[selection_vector]`.") success_msg("Great! This exercise concludes the chapter on vectors. The next chapter will introduce you to the two-dimensional version of vectors: matrices.")

Once you've correctly calculated selection_vector, you can again use roulette_vector[selection_vector] to select the positive results from roulette_vector.

Previous: 2-15 | Selection by comparison - Step 2

Next: 3-1 | What's a matrix?

Back to Main