0% found this document useful (0 votes)
82 views24 pages

R and R Studio Introduction

This document provides information on the R programming language. It discusses that R is a free and open-source programming language popular for statistical analysis and graphics. It can run on Windows, Unix, and MacOS and contains advanced statistical routines. R is both flexible and powerful as a command-driven language suitable for data analysis with simple syntax. Instructions are provided on installing R on Windows and Mac as well as upgrading to specific versions. An overview of RStudio and data objects in R like vectors, matrices, and data frames is also given.

Uploaded by

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

R and R Studio Introduction

This document provides information on the R programming language. It discusses that R is a free and open-source programming language popular for statistical analysis and graphics. It can run on Windows, Unix, and MacOS and contains advanced statistical routines. R is both flexible and powerful as a command-driven language suitable for data analysis with simple syntax. Instructions are provided on installing R on Windows and Mac as well as upgrading to specific versions. An overview of RStudio and data objects in R like vectors, matrices, and data frames is also given.

Uploaded by

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

PRADIPTARATHI PANDA

LECTURER, NISM, MUMBAI


WHY R?
✓It's free!

✓It runs on a variety of platforms including Windows, Unix and MacOS.

✓It contains advanced statistical routines not yet available in other packages.

✓It has state-of-the-art graphics capabilities.

✓R is a command driven computer programming language and is popularly


known as the multipurpose software.

✓The R works in two modes interactive(Command wise) and batch(Run scripts).It


is user friendly and easy to extend with user written functions

✓R can be viewed as a programming language that comes with a large library of


pre-defined functions that can be used to perform various tasks.
ABOUT R AND R STUDIO

➢ R is a free software environment for statistical computing and graphics. It’s open
source and therefore available free of charge.

➢ R studio is a powerful and productive user interface for R. It's free and open
source, and works great on Windows, Mac, and Linux.

➢ R is an object oriented programming language where we create objects and


manipulate them as intended. Objects can be Data frames, vectors, matrices, lists,
raw data, spatial objects , maps etc.
WHY R LANGUAGE
✓R is not just a statistics package, it’s a language(allows you to specify the
performance of new tasks without any limitations)
✓R is designed to operate the way that problems are thought about and has very
simple syntax.
✓ R is both flexible and powerful.
✓It is very interactive and thus suitable for data analysis.
✓R syntax is very simple and intuitive. For instance,
✓ n <- 10 + 2
✓ n
✓ [1] 12
INSTALL R FOR WINDOWS

Go to your browser and search for R 3.5.1 windows

➢ Choose Download R-3.5.1 for Windows

➢ Click, Download R 3.5.1 for windows (64 megabytes, 32/64 bit )

➢ Then, save the file and run it after download is complete.

➢ Click next in all the popups that appear then finish.

Open the installed r


INSTALL R FOR MAC

Go to your browser and search for R 3.5.1 mac


➢Choose R for Mac OS X
➢In the page that opens, click old in the second line
➢Scroll down the page and choose R-3.5.1.pkg
➢Then, save the file and run it after download is complete.
➢Click continue and then install

Open the installed r


INSTALL R STUDIO

✓ Open browser and search for r studio download

✓ Choose Download RStudio –RStudio

✓ Scroll down the page that opens and go to Installers

✓ Choose the download file according to your operating system

✓ Save the file and run it after download is complete.

✓ Click Next and then Finish

✓ Open R studio
UPGRADING R TO A SPECIFIC VERSION

FOR MAC:

• Download and install the new version of R you need.

➢ Go to /Library/frameworks/Rframeworks/versions/<old version>/Resources/library and copy


everything inside.

➢ Paste the above items inside /Library/frameworks/Rframeworks/versions/<new


version>/Resources/library

• Restart R studio

• Write “update.packages()” on the console and execute


UPGRADING R TO A SPECIFIC VERSION
FOR Windows:

• Download and install the new version of R you need.

➢ Go to Libraries\Documents\R\win-library\<old version> and copy everything inside.

➢ Paste the above items inside Libraries\Documents\R\win-library\<new version>Restart R


studio

• Write “update.packages()” on the console and execute


R STUDIO

Data Objects
R SCRIPT

File ,Plots, Package


installation and
CONSOLE (Script Help panels
output panel)
AS AN OBJECT ORIENTED LANGUAGE
• An object can be created with the “assign” operator which is written as an arrow with a minus sign and a bracket; this symbol can be
oriented left-to-right or the reverse:
n <- 15
n
[1] 15
5 -> n
n
[1] 5
x <- 1
X <- 10
x
[1] 1
X
[1] 10
• If the object already exists, its previous value is erased. The value assigned this way may be the result of an operation and/or a function.
n<-3+sqrt(10)
n
[1] 6.162278
SETTING WORKING DIRECTORY

✓ To know the current directory type getwd() without any argument in console.
✓ To change the working directory type setwd() with specified path
✓ setwd ( “path of the directory " )
✓ getwd ( )
DATA TYPES IN R

✓ Vectors
✓ Lists
✓ Matrices
✓ Arrays
✓ Factors
✓ Data Frames
VECTORS

• Vectors: Any object that contains data is called a data structure and numeric
vectors are the simplest type of data structure in R. In fact, even a single number
is considered a vector of length one.

• Very basic data structure in R is vector with three common properties:Type,


Length and Attributes(additional arbitrary metadata)

• The c() or vector() function can be used to create vectors


• Pgpsmn<- c ( 0 . 5 , 0 . 6 ) ## nume r i c
• > pglogic<- c (TRUE, FALSE) ## l o g i c a l
• > pgchr<- c ( "a" , "b" , "c" ) ## c h a r a c t e r
• > pgint<- 9:2 9 ## i n t e g e r
LIST

✓ List: Lists are used to build more complex data structures. Can be created using
list() It creates objects which contain elements of different types like numbers,
strings and vectors
✓ Special type of vectors that can contains elements of different class
✓ X<-(1:70)
✓ Y<-(80:120)
✓ Z<-cbind(X+Y)
MATRIX

✓ Adding a dim() attribute to an atomic vector allows it to behave like an array


✓ The matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE can be used to create
matrix
✓ ma t r i x ( 1 : 6 , nrow = 2 , n c o l = 3)
MATRIX ALGEBRA
FACTORS:

✓ Can be created using factor()


✓ Can think of as integer vector where each integer has a label
✓ Used to represent categorical data
✓ x <-f a c t o r ( c ( " yes " , " yes " , "no" , " yes " , "no" ) )
✓t a b l e ( x )
MISSING VALUES

✓ Missing Values:In R, missing values are represented by the symbol


✓ NA or NaN(not available)
✓ Is.na or is.NaN
✓ Na.omit
DATA FRAMES
✓ Data Frames: Used to store tabular data in R. A special type of list
✓ where every element of the list has same length.
✓ Can store dierent classes of objects in each column unlike matrices
✓ Dataframes can be converted to matrix using as.matrix()

✓ ( x <- data . f rame ( foo= 1 : 4 , bar= c (T, T, F , F ) ) )


✓ Using cbind() and rbind() dataframes can be combined
✓ Dataframes can be created by reading in a dataset using
✓ read.table() or read.csv() and it can also be created explicitly using data.frame() function
✓ l i b r a r y ( Pe r f o rma n c eAn a l y t i c s )
✓ library(rugarch)
✓ l i b r a r y ( FinTS )
✓ l i b r a r y ( rmgarch )
✓ l i b r a r y ( t ime S e r i e s )
✓ library(pastecs)
✓ library(tseries)
✓ l i b r a r y ( Hmisc )
✓ l i b r a r y ( gogar ch )
✓ library(parallel)
✓ l i b r a r y ( fpp )
✓ l i b r a r y ( tsDyn )
✓ l i b r a r y ( dyn )
✓ l i b r a r y ( tsDyn )
✓ l i b r a r y ( fpp )
✓ l i b r a r y ( bas e )
Thank You

You might also like