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:
- What and Why is R Language.
- How to run CloudStat Console.
- Use CloudStat Console as a calculator.
- Some built-in mathematical functions.
- Integer Quotients and Modulo.
- Rounding (Up, down and nearest)
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.
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!
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!
Let’s try some more.
Use this console as a calculator! Type:
And click the “Run” button.
Simple math. 1+1 is 2. You will see something like:
You will get:
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
Let’s try some built-in mathematical functions!
Then, click “Run” button as before to see the output!
You will see
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
Want to use π ? Please type:
Output will be:
You will get:
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!
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
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
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
> 4 %% 2
You use modulo to test if one number,
is an exact multiple of some other number.
to find out whether 72 is a multiple of 8 or 7, ask:
> 72 %% 8 == 0
> 72 %% 7 == 0
72 is a multiple of 8, not 7.
a) Rounding down
b) Rounding up
c) Rounding to the nearest integer
> round(3.4, digits=0)
> round(3.5, digits=0)
Shortcut: Use round(x,0)
> round(3.5, 0)
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!