Variable assignment in R Question 3

R Programming Language / Variable in R Language

694

Program:

# Assign a value to the variables my_apples and my_oranges
my_apples <- 5
my_oranges <- 6

# Add these two variables together
my_apples + my_oranges

# Create the variable my_fruit
my_fruit <- my_apples + my_oranges

Output:

> # Assign a value to the variables my_apples and my_oranges
> my_apples <- 5
> my_oranges <- 6
> 
> # Add these two variables together
> my_apples + my_oranges
[1] 11
> 
> # Create the variable my_fruit
> my_fruit <- my_apples + my_oranges
> # Assign a value to the variables my_apples and my_oranges
> my_apples <- 5
> my_oranges <- 6
> 
> # Add these two variables together
> my_apples + my_oranges
[1] 11
> 
> # Create the variable my_fruit
> my_fruit <- my_apples + my_oranges
> 
> # see result
> my_fruit
[1] 11

Explanation:

  • Assign to my_oranges the value 6.
  • Add the variables my_apples and my_oranges and have R simply print the result.
  • Assign the result of adding my_apples and my_oranges to a new variable my_fruit.

This Particular section is dedicated to Programs only. If you want learn more about R Programming Language. Then you can visit below links to get more depth on this subject.