Lesson 1: Overview of R Language & CloudStat School

[This article was first published on CloudStat, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is the first lesson of CloudStat School, Lesson 1: Overview of R Language & CloudStat School.

The objective of this lesson is introducing R Language and how you can be a R programmer or a data analyst through CloudStat School.

At the end of this lesson 1, you will learn:

  1. What and Why is R Language.
  2. How to run CloudStat Console.
  3. Use CloudStat Console as a calculator.
  4. Some built-in mathematical functions.
  5. Integer Quotients and Modulo.
  6. Rounding (Up, down and nearest)

1. Introduction
1.1 What is CloudStat School?
An online platform for you to learn and do data analysis
with R Language collaboratively and interactively.

1.2 What is R Language?
R is an open source (free!) programming language
that has excellent statistical abilities.
R has Everything you need in terms of data analysis.

1.3 Prerequisites & Preparations
All you need is Internet Access! That’s all!
There is no download, installation, updates or maintenance needed.

1.4 Alert!
R is a language, like Italian, Dutch, Spanish, English, or Chinese.
If you try to proceed too rapidly, use the wrong reading material, or
have the wrong teacher, then, yes, mastering R may be challenging.
So be fun and enjoy the learning process!

1.5 Overview
You will see a console box at your left hand side.
Below is the output box. Anything you “Run”
in console box will be shown as a result in the output box.

There is a default command in the console box:
x = -100:100; plot(x^2)
Now, give it a try, just click “Run” to see what’s happening!

Yes! You’re plotting a quadratic function, x2 graph as below!

Let’s try some more.
Use this console as a calculator! Type:
1+1

And click the “Run” button.
Simple math. 1+1 is 2. You will see something like:
> 1+1
[1] 2

Try more:

12+43
56-12
5*6
63/7

“Run” it!

You will get:
> 12+43
[1] 55
> 56-12
[1] 44
> 5*6
[1] 30
> 63/7
[1] 9

Let’s do it in one line.
Just remember separate them with semi-colons ;

12+43; 56-12; 5*6; 63/7

Then, click “Run” button to see the result.

You will see something like:

> 12+43; 56-12; 5*6; 63/7
[1] 55
[1] 44
[1] 30
[1] 9

Let’s try some built-in mathematical functions!

exp(12)
log(12)
sin(12)

Then, click “Run” button as before to see the output!

You will see

> exp(12)
[1] 162754.8
> log(12)
[1] 2.484907
> sin(12)
[1] -0.5365729

There are more! You can try:
log(x) = log to base e of x
exp(x) = antilog of x ex
log(x,n) = log to base n of x
log10(x) = log to base 10 of x
sqrt(x) = square root of x
cos(x) = cosine of x in radians
atan(x) = inverse trigonometric transformations
More…

Want to use π ? Please type:

pi

Output will be:

> pi
[1] 3.141593

Type:
cos(pi/2)

You will get:
> cos(pi/2)
[1] 6.123234e-17

The e-17 means times 10−17.

Numbers with Exponents
For very big numbers or very small numbers:

2.4e3 means 2400
4.8e-2 means 0.048
8.2+3.4i is a complex number with real (8.2) and imaginary (3.4) parts

Just try typing the red command into the console box to see the output!

Modulo (Remainder)
Now suppose we wanted to know the remainder,
(what is left over when 234 is divided by 7),
in maths this is known as modulo.
Use %% (percent, percent)

> 234 %% 7
[1] 3

Integer Quotients
How’s about the integer part of a division,
for last example, how many 7s are there in 234?
Use %/% (percent, divide, percent)

> 234 %/% 7
[1] 33

Modulo is very useful for testing if odd or even:
odd numbers have modulo 2 value 1 
even numbers have modulo 2 value 0

> 7 %% 2
[1] 1
> 4 %% 2
[1] 0

You use modulo to test if one number,
is an exact multiple of some other number.
For instance:
to find out whether 72 is a multiple of 8 or 7, ask:
> 72 %% 8 == 0
[1] TRUE
> 72 %% 7 == 0
[1] FALSE
72 is a multiple of 8, not 7.

Rounding
a) Rounding down
> floor(3.4)
[1] 3

b) Rounding up
> ceiling(3.4)
[1] 4

c) Rounding to the nearest integer
> round(3.4, digits=0)
[1] 3
> round(3.5, digits=0)
[1] 4

Shortcut: Use round(x,0)
> round(3.5, 0)
[1] 4

So, hope you have learnt some of the basics!

Please join us @ CloudStat School Forum
to discuss the issues, i.e. problems, suggestions,
feedback about CloudStat School!

Please share about us to your friends too!
Thank you!

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 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.

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)