Variables

  • You can create variables to store data. Variables have arbitrary names, so you can call them whatever you want. To create a variable, provide it's name (in this case six), then the assignment operator <- and some value. Let's create a variable called "six" and give it the value of "6". Therefore, we would type: six<-6

 

 

  • Now we can use this "six" variable as if it were any other number.

 

  • In the script you should type in the following: six + 3

 

 

  • In the console, you should see the answer as 9.

 

 

  • You can use whatever names you want and it'll still work.

 

  • For example, try it out by making the variable "blue" the value of the number 4. Therefore, we would type:
  • blue<-4
  • six + blue

 

 

 

  • On the top right hand side if you look at values, you will now see the two variables (six and blue) with the value that it represents.