R Programming/Sample Session

This page is an introduction to the R programming language. It shows how to perform very simple tasks using R. First you need to have R installed (see the Settings page). If you use Windows or Mac OS, the easiest solution is to use the R Graphical User Interface (click on its icon). If you use Linux, open a terminal and type  at the command prompt.

Usually when you open R, you see a message similar to the following in the console:

You can type your code after the angle bracket.

R can be used as a simple calculator and we can perform any simple computation.

We can also store numeric or string objects using the assignment operator,.

We can also store vectors.

We can also describe the vector with length, mean and var.

We can also define a matrix.

We can plot the data using plot.

We can define a dataframe.

You can save an R session (all the objects in memory) and load the session.

We can define a working directory. Note for Windows users : R uses slash ("/") in the directory instead of backslash ("\").

There are some special characters in R For instance 0 divided by 0 gives a NaN but 1 divided by 0 gives $$+\infty$$
 * NA : Not Available (i.e. missing values)
 * NaN : Not a Number (e.g. 0/0)
 * Inf: Infinity
 * <tt>-Inf</tt> : Minus Infinity.

We can exit R using <tt>q</tt>. The <tt>no</tt> argument specifies that the R session is not saved.