0% found this document useful (0 votes)
10 views5 pages

Experiment OEC

Uploaded by

Sidharth Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Experiment OEC

Uploaded by

Sidharth Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

R PROGRAMMING

Experiment -I

Aim: To Install R and R Packages

Objective: To understand how to install R ,RStudio and its packages

1. Open an internet browser and go to www.r-project.org.

2. Click the "downloadR"linkin the middleofthe page under "Getting Started."

3. Select a CRAN location (a mirrorsite) and click the correspondinglink.

4. Click on the "DownloadRfor WINDOWS" link at the top ofthe page.

5. Click on the file containing the latest version ofR under "Files."

6. Save the .pkgfile, double-click it to open, and followthe installation instructions.

7. Now that R isinstalled, you need to download and installRStudio.

To Install RStudio

1. Go to www.rstudio.comand clickon the "DownloadRStudio"button.

2. Click on "Download RStudioDesktop."

3. Click on the version recommended for yoursystem, or the latest Mac version,save the

.dmg file on your computer, double-click it to open, and then drag and drop it to your

applicationsfolder.

To Install R Packages

The capabilities of R are extended through user-created packages, which allow specialized

statistical techniques, graphical devices, import/export capabilities, reporting tools (knitr,

Sweave), etc. These packages are developedprimarilyinR, and sometimesin Java,C,C++, and

Fortran.TheR packaging system is also used by researchers to create compendia to organise

research data, code and reportfilesin a systematic way forsharing and public archiving.

A core set of packages is included with the installation of R, with more than 12,500 additional

packages (as of May 2018[update]) available at the Comprehensive R Archive Network

(CRAN).

Packages are collections of Rfunctions,data, and compiled codein a well- defined format. The

directory where packages are stored is called the library.R comes with a standard set of

packages. Others are available for download and installation.Once installed, they have to be

loaded into the session to be used.


R PROGRAMMING
.libPaths() # get library location library() # see

all packages installed

search() # see packages currentlyloaded

Adding R Packages

You can expand the types of analyses you do be addingother packages. A complete list of

contributed packages is available fromCRAN.

Follow these steps:

R PROGRAMMING

1. Download and install a package (you only need to do this once).To use the package,

invoke the library(package) command to load it into the current session. (You need

to do this once in each session, unless you customizeyour environmenttoautomatically

load it each time.)

Installing and Loading Packages

It turns out the ability to estimate ordered logistic or probit regression is included in the

MASS package.

To install this package you run the followingcommand: 1 > install .

packages(" MASS")

You will be asked to pick a CRAN mirror from which to download (generally the closer

the faster) and R will install the package to your library.R willstill be clueless. To actually

tell Rto use the new package you have to tell R to load the package’s library each time you

start an R session, just likeso:

1 > library (" MASS ")

>

R nowknowsall the functionsthat are canned in the MASSpackage. To see what functions

are implemented in the MASS package, type:

1 > library ( help = " MASS ")

>

Maintaining your Library


R PROGRAMMING
Packages are frequently updated. Depending on the developer this could happen very often.

To keep your packages updated enterthis every once in a while:

1 > update . packages ( )

The Workspace

The workspace is your current R working environment and includes any user-definedobjects

(vectors,matrices, data frames,lists,functions).Atthe end of an R session, the user can save an

image of the current workspace that is automatically reloaded the next time R is started.

Commands are entered interactively at the R user prompt. Up and down arrow keys scroll

through your command history.

You will probably want to keep differentprojects in differentphysical directories. Here are

some standard commands for managing your workspace.

getwd( ) # print the current working directory . ls ( ) # list

the objects in the currentworkspace.

Setwd (mydirectory) # change to mydirectory

setwd ("c:/docs/mydir") # note / instead of \ in windows

# view and set options for the session help(options)# learn

R PROGRAMMING

about available options options() # view current option

settings

Conclusion: Student are able to install R and its packages.


R PROGRAMMING
Experiment -2

Aim:

Demonstration of declaring R variables

Objective:

1) Student is able to work on variables, objects, expressions

2)Work on vectors and its operations

3)Read and write data to R

DATA TYPES

You may like to store information of various data typeslike character, wide character, integer,

floatingpoint,doublefloatingpoint,Booleanetc.Based on the data type of a variable, the

operating system allocates memory and decides what can be stored in the reservedmemory.

The variables are assigned with R-Objects and the data type of the R-object becomes the data type of

the variable. There are many types of R-objects. The frequently used ones are −

• Vectors:A basic data structure of R containingthe same type of data.

• Matrices:Amatrix is a two-dimensionalrectangular data set. It can be created using a

vector inputto the matrix function.

• Factors: Factors are the r-objects which are created using a vector. It storesthe vector

along with the distinct values of the elements in the vector as labels. The labels are

always character irrespective of whether it is numericor character or Boolean etc. in the

input vector. They are useful in statisticalmodelling.

• Data Frames: Data frames are tabular data objects. Unlike a matrix in data frame each

column can contain different modes of data. The first column can be numeric while the

second column can be character and third column can be logical. It is a list of vectors of

equal length.

• Lists:A list is an R-object which can contain many different types of elements inside it

like vectors, functions and even another list inside it.


R PROGRAMMING
> x <- c(1, 5, 4, 9, 0)
> typeof(x)
[1] "double"
> length(x)
[1] 5
> x <- c(1, 5.4, TRUE, "hello")
>x
[1] "1" "5.4" "TRUE" "hello"
> typeof(x)
[1] "character"

You might also like