DR.
PRADIPTARATHI PANDA
ASSISTANT PROFESSOR, 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.
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 4.1.1 windows
➢ Choose Download R-4.1.1 for Windows
➢ Click, Download R 4.1.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 4.1.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 [Link]
➢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 “[Link]()” 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 “[Link]()” 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)
✓ [Link] or [Link]
✓ [Link]
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 [Link]()
✓ ( 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
✓ [Link]() or [Link]() and it can also be created explicitly using [Link]() 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