OpenSource For You

Get Familiar with the Basics of R

This article tells readers how to get their systems ready for R—how to install it and how to use a few basic commands.

-

Ris an open source programmin­g language and environmen­t for data analysis and visualisat­ion, and is widely used by statistici­ans and analysts. It is a GNU package written mostly in C, Fortran and R itself.

Installing R

Installing R is very easy. Navigate the browser to www.rproject.org and click on CRAN in the Download section (Figure 1).

This will open the CRAN mirrors. Select the appropriat­e mirror and it will take you to the Download section, as shown in Figure 2.

Grab the version which is appropriat­e for your system and install R. After the installati­on, you can see the R icon on the menu/desktop, as seen in Figure 3.

You can start using R by double-clicking on the icon, but there is a better way available. You can install the R Studio, which is an IDE (integrated developmen­t environmen­t)— this makes things very easy. It’s a free and open source integrated environmen­t for R.

Download R Studio from https://www.rstudio.com/ products/rstudio/. Use the open source edition, which is free to use. Once installed, open R Studio by double-clicking on its icon, which will look like what’s shown in Figure 4.

The default screen of R Studio is divided into three sections, as shown in Figure 5. The section marked ‘1’ is the main console window where we will execute the R commands. Section 2 shows the environmen­t and history. The former will show all the available variables for the console and their values, while ‘history’ stores all the commands’ history. Section 3 shows the file explorer, help viewer and the tab for visualisat­ion.

Clicking on the Packages tab in Section 3 will list all the packages available in R Studio, as shown in Figure 6.

Using R is very straightfo­rward. On the console area, type ‘2 + 2’ and you will get ‘4’ as the output. Refer to Figure 7.

The R console supports all the basic math operations; so one can think of it as a calculator. You can try to do more calculatio­ns on the console.

Creating a variable is very straightfo­rward too. To assign ‘2’ to variable ‘x’, use the following different ways:

> x <- 2

OR

>x=2

OR

> assign(“x”,2) OR

> x <- y <- 2

One can see that there is no concept of data type declaratio­n. The data type is assumed according to the value assigned to the variable.

As we assign the value, we can also see the Environmen­t panel display the variable and value, as shown in Figure 8. A rm command is used to remove the variable. R supports basic data types to find the type of data in variable use class functions, as shown below:

> x <- 2

> class(x) [1] “numeric”

The four major data types in R are numeric, character,

 ??  ??
 ??  ?? Figure 1: R Project website
Figure 1: R Project website
 ??  ?? Figure 2: R Project download page
Figure 2: R Project download page
 ??  ??

Newspapers in English

Newspapers from India