Lesson 2: Values & Variables (CloudStat School)

January 8, 2012

(This article was first published on CloudStat, and kindly contributed to R-bloggers)

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):
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 +
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.

To leave a comment for the author, please follow the link and comment on their blog: CloudStat.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , ,

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)