Get Fa­mil­iar with the Ba­sics of R

This ar­ti­cle tells read­ers how to get their sys­tems ready for R—how to in­stall it and how to use a few ba­sic com­mands.

OpenSource For You - - Contents -

Ris an open source pro­gram­ming lan­guage and en­vi­ron­ment for data anal­y­sis and vi­su­al­i­sa­tion, and is widely used by statis­ti­cians and an­a­lysts. It is a GNU pack­age writ­ten mostly in C, For­tran and R it­self.

In­stalling R

In­stalling R is very easy. Nav­i­gate the browser to www.rpro­ and click on CRAN in the Down­load sec­tion (Fig­ure 1).

This will open the CRAN mir­rors. Se­lect the ap­pro­pri­ate mir­ror and it will take you to the Down­load sec­tion, as shown in Fig­ure 2.

Grab the ver­sion which is ap­pro­pri­ate for your sys­tem and in­stall R. Af­ter the in­stal­la­tion, you can see the R icon on the menu/desk­top, as seen in Fig­ure 3.

You can start us­ing R by dou­ble-click­ing on the icon, but there is a bet­ter way avail­able. You can in­stall the R Stu­dio, which is an IDE (in­te­grated de­vel­op­ment en­vi­ron­ment)— this makes things very easy. It’s a free and open source in­te­grated en­vi­ron­ment for R.

Down­load R Stu­dio from https://www.rstu­ prod­ucts/rstu­dio/. Use the open source edi­tion, which is free to use. Once in­stalled, open R Stu­dio by dou­ble-click­ing on its icon, which will look like what’s shown in Fig­ure 4.

The de­fault screen of R Stu­dio is di­vided into three sec­tions, as shown in Fig­ure 5. The sec­tion marked ‘1’ is the main con­sole win­dow where we will ex­e­cute the R com­mands. Sec­tion 2 shows the en­vi­ron­ment and his­tory. The for­mer will show all the avail­able vari­ables for the con­sole and their val­ues, while ‘his­tory’ stores all the com­mands’ his­tory. Sec­tion 3 shows the file ex­plorer, help viewer and the tab for vi­su­al­i­sa­tion.

Click­ing on the Pack­ages tab in Sec­tion 3 will list all the pack­ages avail­able in R Stu­dio, as shown in Fig­ure 6.

Us­ing R is very straight­for­ward. On the con­sole area, type ‘2 + 2’ and you will get ‘4’ as the out­put. Refer to Fig­ure 7.

The R con­sole sup­ports all the ba­sic math op­er­a­tions; so one can think of it as a cal­cu­la­tor. You can try to do more cal­cu­la­tions on the con­sole.

Cre­at­ing a vari­able is very straight­for­ward too. To as­sign ‘2’ to vari­able ‘x’, use the fol­low­ing dif­fer­ent ways:

> x <- 2




> as­sign(“x”,2) OR

> x <- y <- 2

One can see that there is no con­cept of data type dec­la­ra­tion. The data type is as­sumed ac­cord­ing to the value as­signed to the vari­able.

As we as­sign the value, we can also see the En­vi­ron­ment panel dis­play the vari­able and value, as shown in Fig­ure 8. A rm com­mand is used to re­move the vari­able. R sup­ports ba­sic data types to find the type of data in vari­able use class func­tions, as shown be­low:

> x <- 2

> class(x) [1] “nu­meric”

The four ma­jor data types in R are nu­meric, char­ac­ter,

Fig­ure 1: R Pro­ject web­site

Fig­ure 2: R Pro­ject down­load page

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.