Suppose you have a fruit basket with five apples. As a data analyst in training, you want to store the number of apples in a variable with the name my_apples.
my_apples <- 5. This will assign the value 5 to my_apples.my_apples below the second comment. This will print out the value of my_apples.my_apples to the value 5.
# Assign the value 5 to the variable my_apples
# Print out the value of the variable my_apples
# Assign the value 5 to the variable my_apples
my_apples <- 5
# Print out the value of the variable my_apples
my_apples
test_object("my_apples",
undefined_msg = "Please make sure to define a variable `my_apples`.",
incorrect_msg = "Make sure that you assign the correct value to `my_apples`.")
test_output_contains("my_apples", incorrect_msg = "Have you explicitly told R to print out the `my_apples` variable to the console?")
success_msg("Great! Continue to the next exercise!")
Remember that if you want to assign a number or an object to a variable in R, you can make use of the assignment operator <-. Alternatively, you can use =, but <- is widely preferred in the R community.