Vector selection: the good times (3)

Selecting multiple elements of poker_vector with c(2, 3, 4) is not very convenient. Many statisticians are lazy people by nature, so they created an easier way to do this: c(2, 3, 4) can be abbreviated to2:4, which generates a vector with all natural numbers from 2 up to 4.

So, another way to find the mid-week results is poker_vector[2:4]. Notice how the vector 2:4 is placed between the square brackets to select element 2 up to 4.

Instruction

Assign to roulette_selection_vector the roulette results from Tuesday up to Friday; make use of : if it makes things easier for you.

# 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 # Define a new variable based on a selection roulette_selection_vector <- # 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 # Define a new variable based on a selection roulette_selection_vector <- roulette_vector[2:5] 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("roulette_selection_vector", undefined_msg = "Please make sure to define a variable `roulette_selection_vector`.", incorrect_msg = "It looks like `roulette_selection_vector` does not contain the correct selection from `roulette_vector`. Make sure to to use the right indexes.") success_msg("Awesome! The colon operator is extremely useful and very often used in R programming, so remember it well. Proceed to the next exercise.")

Assign a selection of roulette_vector to roulette_selection_vector by placing 2:5 between square brackets.

Previous: 2-11 | Vector selection: the good times (2)

Next: 2-13 | Vector selection: the good times (4)

Back to Main