Variable assignment (2)

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.

Instruction

# 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.

Previous: 1-3 | Variable assignment

Next: 1-5 | Variable assignment (3)

Back to Main