Lesson 2: Values & Variables (CloudStat School)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This is the second lesson of CloudStat School, Lesson 2: Values & Variables.
At the end of the lesson 2, you should know:
1. Inserting values into valuables
2. Calling valuables
3. Simple operation within variables.
2.1 Assign/Insert Values into Variables
There are 2 symbols can be used:
i) less than minus, <-
abc <- 123
ii) equal, =
xyz = 321
By typing these commands, you are assigning the
value of 123 into variable abc. Same as 321 into xyz.
2.2 Calling Values from Variables.
To see the values have been assigned into variables,
we need to call them.
To call values from variables, simply type variables’ names.
In this case (from 2.1):
abc
xyz
Click “Run” button to see the result.
2.3 Assign & Call Variables
> abc <- 123
> xyz = 321
> abc
[1] 123
> xyz
[1] 321
You have assigned the values of 123 and 321
into abc and xyz repectively.
2.4 Simple Mathematic Operation with Variables
The common math operators are
plus +
minus –
multiple *
division /
Remain the last commands, type and run:
abc + xyz
xyz – abc
You will see:
> abc + xyz
[1] 444
> xyz – abc
[1] 198
abc + xyz means 123 + 321, so you got 444
xyz – abc means 321 – 123, you got 198
That’s just for warm-up!
But hope you had learnt about:
1. Inserting values into valuables
2. Calling valuables
3. Simple operation within variables.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.