home | non-tech | cs | ee | about
Abstract New

Getting started with R programming - A quick tutorial

R is a programming language and development environment for statistical computing and graphics. R is derived from S (a statistical programming language developed at Bell Labs). A friend of mine mentioned (I am too lazy to check Wikipedia) that R is named after the first names of the authors – Oh the pomposity. Joking aside, R is a very powerful programming language that greatly eases the development of statistical software for big data analysis.

Installing R

You can download R from here. Windows users - R comes in a 50 MB exe file that you download. R is available both for 32 bit and 64 bit OS versions. The installation is fairly straightforward.

R packages

R can be easily extended via user developed packages. At the time of writing this post R has around 5000 add on packages. Translation: The R community is awesome. To look at available packages select install packages from the package menu and pick a mirror from where to download.

Installing R packages

Plotting a sine wave using R – Code with comments that are (hopefully) explanatory

The sine wave is the hello world of mathematics, physics, engineering…(I could go on). Let us begin our learning of R by plotting this venerable curve.


//the seq command generates sequences of numbers with the given step
t = seq(0, 10, by=0.001);

//set frequency to 1
freq = 1;

//the sine wave of frequency 1 hz
x = sin(2 * pi * freq *  t);

//plot the sine wave
plot(t,x);

//turn on grid lines in a plot 
grid();

Voila - the sine wave
Sine wave R programming

Some helpful R functions

help(functionname) Shows the help documentation for the function
Ctrl + L Clears the R console
ls() Lists the local variables
search() Shows a list of packages
rm(objectname) Removes an object from memory

No comments:

Post a Comment

© 2014 - 2015 abstract new. All rights reserved.