Get startedGet started for free

Apples and oranges

Common knowledge tells you not to add apples and oranges. But hey, that is what you just did, no :-)? The my_apples and my_oranges variables both contained a number in the previous exercise. The + operator works with numeric variables in R. If you really tried to add "apples" and "oranges", and assigned a text value to the variable my_oranges (see the editor), you would be trying to assign the addition of a numeric and a character variable to the variable my_fruit. This is not possible.

This exercise is part of the course

Introduction to R

View Course

Exercise instructions

  • Submit the answer and read the error message. Make sure to understand why this did not work.
  • Adjust the code so that R knows you have 6 oranges and thus a fruit basket with 11 pieces of fruit.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Assign a value to the variable my_apples
my_apples <- 5 

# Fix the assignment of my_oranges
my_oranges <- "six" 

# Create the variable my_fruit and print it out
my_fruit <- my_apples + my_oranges 
my_fruit
Edit and Run Code