Welcome to the spoken tutorial on basics of R.
In this tutorial, we hope to provide a feel for R and Rstudio
How can R be used as a calculator?
How to use built-in functions like sin and log?
Introduction to vector operations
Introduction to plotting
Taking help in RStudio and
Where to get more information on R and Rstudio
To understand this tutorial, one needs to know elementary maths.
For example, log, sine and plotting
Please locate this tutorial on our website, spoken tutorial dot org
We provide many useful supplementary material in this page
No programming background is required, however, to understand this tutorial
I am using version 3 of R,Using RStudio 0.97
R and RStudio work on web browsers also
Hence, these are easily accessible from every operating system, including Aakash
Let us continue with system requirements.
For this tutorial, I am using Mac OS X 10.7.4
But the usage is similar in Linux and Windows as well
Let us give a quick introduction to R.
R is an outstanding software for general computations
It is especially suitable for statistical computing
It is an alternative to SPSS
It is a free and open source software
It can be downloaded from c ran dot r dash project dot org
Let us now give a quick introduction to Rstudio
RStudio is a friendly front-end to R
It is a free and open source software
It can be downloaded from rstudio dot com
A two minute video by the RStudio team is available here.
Let me return to the slides.
RStudio also runs on a web browser.
Here is a screenshot of R and RStudio on a web server, accessed from Aakash
Let us do a practice session on R, using Rstudio
You now see RStudio on the screen.
I have shrunk its size quite a bit, to fit into a small screen.
Please use a size you are comfortable with.
I have also enlarged the font size, so that the recording is clear.
You do this on Windows and Linux, by pressing control and + keys together.
For this tutorial, I want to maximise the size of the console of Rstudio.
I do this by pressing the maximise button in the console window.
I also maximise the right lower window of RStudio in a similar manner.
Let me begin multiplying two numbers two point one and five.
R gives the answer in black as ten point five.
I want to divide this by three.
I will recall the previous command by clicking the up arrow.
What I typed earlier, namely two point one into five appears.
I will divide this by three to get the answer three point five.
I can add two numbers.
I can store the result in a variable using the assignment operator.
Less than symbol followed by hyphen.
One can also use an equal sign.
If I want to see what is in a variable, I just type the variable name.
In this case, I type a and see that it has five.
I will subtract zero point one six from a.
I will raise it to the power of zero point 5.
Remember, I have to put a minus zero point one six within brackets, to get the correct answer.
We get two point two, as expected.
Using the left and right arrows, I moved the cursor back and forth within a command.
I can also carry out the same calculation using the function call, square root.
I will find the value of e by using the function call, exp.
You may have noticed, the moment I open a bracket, R automatically closes it.
This eliminates errors due to unmatched brackets. So, we see the value of e above.
I can find the natural logarithm of e with the help of the log function.
The value is one, as expected
How do we find the log to the base ten?
Use the command log10.
Ten to the power five.
This gives the answer as five, as expected.
What happens if I forget the ten in log10?
We get a different answer.
It is easy to verify that this answer is correct for natural logarithm.
Can you please suggest a method to verify this?
There is another way to find the logarithm to the base of 10.
Give the base as the second parameter, as I do here.
We get five, as expected.
It is easy to create vectors in R.
z = s e q -1 comma 2 comma 0:5
This creates a vector starting at minus one, going up to two, in increments of point five s e q denotes sequence.
Let us see the value of z.
We will see other ways to create vectors in another tutorial.
We can calculate the length of the vector z using the command length:
We get the result seven, as expected.
We will now discuss pi.
The value of pi, is stored in the variable pi, p i, which we can see now.
Let us create a vector x to start from minus two pi, go up to plus two pi, in increments of one.
Please remember to put the multiply sign.
Let us see what x contains
Let us find the sine of this vector using sin and store it in y.
We can work directly with vectors in R, as we did above.
Let us see what y contains.
Let us plot sin(x) versus x, with type=L argument added.
Note that x comes first and then y.
This plot starts from zero as expected, because sin of minus two pi is zero.
The plot is not smooth, as there are not many points.
Let us now get more points by lowering the increment number to point one.
What happens if I try to plot without recalculating y?
R will complain that the lengths are unequal.
You should pause the video and confirm that the lengths are unequal.
Let me recalculate y.
Let me re-plot this curve.
You can see that the plot is smoother now.
Please pause the video now and look at the values stored in x and y.
Please confirm that these values are as per expectation.
We see the lengths of x and y to be 126.
You should verify that these lengths are correct.
You should also display the values of x and y and verify.
If we drop the type parameter in the previous command, we get a plot with points.
Let us press the help button in the right hand side window.
Let us type plot next to the lens symbol and hit return.
Let us scroll.
One can see different choices for the type parameter.
We have come to the end of this tutorial.
Let us see a few low cost books on R.
In this tutorial we learnt about, a few elementary operations
Introduction to plotting
Introduction to help
URLs and books on R and Rstudio
We now suggest an assignment
Find answers to log2 (2^5) and log (e^2)
Please explain your answers
Explore the Help tab in RStudio: Change the labels, title, etc.
Hint: try the plot command with x l a b argument
Copy paste a few examples provided in Help and see what they do
This video summarises the Spoken Tutorial project.
If you do not have good bandwidth, you may download and watch it.
We conduct workshops using Spoken Tutorials.
Give Certificates.
Please contact us.
The Spoken Tutorial project is funded by MHRD, Gov. of India
Thanks for joining, goodbye