SlideShare a Scribd company logo
THE R LANGUAGE FOR
STATISTICAL COMPUTING
Lecture 2
Dr. Syed
Muhammad Ali
Tirmizi
Chapter No. 2
1
2
INTRODUCTION
 R language has its roots at AT&T Bell
Laboratories during the 1970s and 1980s in the
S language project (Becker, Chambers, and
Wilks, 1988).
 People think that the S language would not have
been designed in the way it was if it had been
designed by computer scientists (Morandat, Hill,
Osvald, and Vitek, 2012).
3
INTRODUCTION
 R is an open source variant of S developed at the
University of Auckland by Ross Ihaka and Robert
Gentleman, first appearing in 1993 (Ihaka, 1998).
 Clearly the recent popularity of R, fueled by its
open source availability and the need for statistical
and analytical computing tools, shows that the
benefits of R far outweigh the negatives.
 Overall, R is based upon the vector as a first class
item in the language.
4
INTRODUCTION
 R shares this attribute with LISP, Scheme,
Python, and Matlab.
 This and the prevalence of over 4,000 publicly
available packages are two of the many
strengths of R.
 In this course, we will focus on R packages that
revolve around financial analytics.
5
GETTING STARTED WITH R
 One of the great things about R is how easy it is to install.
 In your browser, head to the web site for the Comprehensive R
Archive Network (CRAN), http://cran.r-project.org
 This website will help you to download and install R software for
windows.
 Just as a basic test, we can create a vector of prices and plot it with
this block of code:
x = c(1.3,1.2,1.3,NA,1.4,1.5)
plot(x,ylab="EUR prices")
is.na(x)
[1] FALSE FALSE FALSE TRUE FALSE FALSE
6
GETTING STARTED WITH R
 The c() operator creates a vector of elements.
 This is the basic vector operator in R.
 Note the “not available” (NA) element
appearing as the fourth item of the vector.
 R’s ability to handle NAs, infinite values (Inf),
and not a number (NaN) is one of its many
strengths.
7
GETTING STARTED WITH R
 A later development is the R Studio GUI available
from the web site www.rstudio.com.
 R Studio is a commercially developed GUI allowing
management of plot windows, variable contents,
and better debugging than the basic R interpreter.
 R Studio is a second-generation R user interface
with integrated code, execution, variable inspection,
and plotting windows, and expression completion.
8
9
GETTING STARTED WITH R
 Any time a library statement is encountered, R
will check that the package is available.
 If not, it must be downloaded.
 As an example, to download the ggplot2
package, use the following command:
update.packages()
install.packages("ggplot2",dependencies=TRUE)
library(ggplot2)
10
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 For many use cases, R provides a computational
statistics platform.
 Mathematical functions are readily available. The
basic log() function provides a natural logarithm.
Of course, executing log() on a vector, x, results
in a vector of natural logarithms, y.
11
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 The computation of log() on NA is NA as expected.
> #Filter prices:
> x[x > 1.3]
[1] NA 1.4 1.5
> #Keeps the NA intact:
> y <- diff(log(x))
> round(y,3)
[1] -0.080 0.080 NA NA 0.069
12
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 In R, not only vectors but also functions are first-
class objects. It shares this attribute with the
functional languages LISP and Scheme.
 Assigning a function to a variable is the usual
way to define it. If g is assigned to the function
definition, then g(4) will evaluate it and g,
without parentheses, will return its definition.
13
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES

14
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 R has four assignment operators.
 The most basic operator is “<-”. This is the one
we use in the first assignment in the code block
below.
 R’s functional nature is so strong that even this
can be replaced by the function call assign(“x”,1).
15
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 Over time, because people were used to other
languages that use “=” instead, and even though
“=” was used to assign parameter values in
function calls (g(x, y = 7), for example), it was
also made available for assignment in R.
 So using “<-” or “=” is now really a matter of
preference.
16
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
> x <- 1
> assign("x",2)
> x
[1] 2
> x = 3
> x
[1] 3
> f <-function(x)
+ {
+ x = 4
+ x
+ }
> f(x)
[1] 4
> x
[1] 3
RUN THESE
CODES
17
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 R’s fourth assignment operator, with two “<”s, is
known as the “super-assignment” operator.
 Executing it will look outside the current frame
for x, which is global to the function f , and
assign to that x.
 If there is no x in the global environment, it will
create one and assign the value to it.
18
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
> #The fourth type is "<<-"
> x = 3
> x
[1] 3
> f <-function(x)
+ {
+ x <<- 4
+ x
+ }
> f(x)
[1] 4
> x
[1] 4
> typeof(f)
[1] "closure"
> typeof(x)
[1] "double"
RUN THESE
CODES
19
LANGUAGE FEATURES: FUNCTIONS,
ASSIGNMENT, ARGUMENTS, AND TYPES
 R is dynamically typed so that variables do not have types.
 Instead, values have types.
 So we can see that the type of a variable is determined by
the type of its current value.
 The function typeof() can be used to return the type of the
value assigned to a variable.
 We can see its use in the output block above: typeof(f) is a
“closure” for a function while typeof(x) is a “double.”
20
LANGUAGE FEATURES:
BINDING AND ARRAYS
 Binding scalars or vectors together is one way to return
aggregate results from functions.
 For binding, cbind() binds items into two columns and
rbind() binds items into two rows.
 If the two items are scalars then the two operations are
equivalent. rep() is a very common function to create a
vector of repeated items.
 For example, rep(4, 5) == c(4, 4, 4, 4, 4) is TRUE and
states to repeat 4 five times.
21
LANGUAGE FEATURES:
BINDING AND ARRAYS
> #Create two column matrix:
> A = cbind(rep(x,length(y)),y)
> A
y
[1,] 4 -0.08004271
[2,] 4 0.08004271
[3,] 4 NA
[4,] 4 NA
[5,] 4 0.06899287
> B = rbind(rep(x,length(y)),y)
> B
[,1] [,2] [,3] [,4] [,5]
4.00000000 4.00000000 4 4 4.00000000
y -0.08004271 0.08004271 NA NA 0.06899287
> t(A) == B
[,1] [,2] [,3] [,4] [,5]
TRUE TRUE TRUE TRUE TRUE
y TRUE TRUE NA NA TRUE
> sum(t(A) == B)
[1] NA
RUN THESE
CODES
22
ERROR HANDLING
 Error handling is an important part of data science, in
order to keep erroneous data from making its way into the
variables and to keep the dataset as clean as possible.
 When calling certain packages, it is common to have
errors returned. R has a tryCatch() feature which is
implemented as a function.
 Example, we use division by zero as the type of error
handled.
23
ERROR HANDLING
#Exception handling:
fh <- 0
tryCatch({
#main block
fh <<- file("file1.txt", open="r")
}, warning = function(w) {
#warning-handler-code
print(w)
fh <<- NA
}, error = function(e) {
#error-handler-code
print(e)
fh <<- NA
}, finally = {
#cleanup-code
})
if(!is.na(fh)) readLines(fh)
RUN THESE
CODES
24
NUMERIC, STATISTICAL,
AND CHARACTER FUNCTIONS
 To set the mode of calculations, options(digits = n) sets
the number of digits to round to in calculations.
#Setting precision:
options(digits=10)
pi = 3.1415926535897932384626
pi
 [1] 3.141592654
25
NUMERIC, STATISTICAL,
AND CHARACTER FUNCTIONS
 Distributions of random variates are available readily
within the language with runif() for the Uniform
Distribution, rnorm() for the Normal Distribution, and
rbinom() for the Binomial Distribution, to name just
three.
 Histograms and density plots are also native to the
language with hist() and density().
26
NUMERIC, STATISTICAL,
AND CHARACTER FUNCTIONS
plot(density(rbinom(50,50,1/2))
options(digits=6)
set.seed(99)
sample(10, replace = TRUE)
[1] 6 2 7 10 6 10 7 3 4 2
27
DATA FRAMES AND INPUT–OUTPUT
 Data frames are one of R’s more unusual and handy
features.
 A data frame is a sequence of rows where the columns are
heterogeneously typed. A common way of loading data
frames is from the Excel .csv files.
#Input-ouput:
write.csv(d,file="d.txt",row.names=FALSE)
e <- read.csv("d.txt",header=TRUE)
28
LISTS
 Lists are ordered aggregates like vectors, which are
constructed by c(. . .).
 However, lists differ from the basic vectors, in that they
are recursively formed, using list(. . .).
#Lists:
c(1,c(1,2),3,"A",c(4,5))
[1] "1" "1" "2" "3" "A" "4" "5"
list(1,c(1,2),3,"A",list(4,5))
THANK YOU
29

More Related Content

What's hot

Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
BBDITM LUCKNOW
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
Shine Raj
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
Durga Padma
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
C program
C programC program
C program
AJAL A J
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
Anshul Sharma
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
gajendra singh
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
Open Gurukul
 
C Programming
C ProgrammingC Programming
C Programming
Adil Jafri
 
C language
C languageC language
C language
spatidar0
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
Vipul Naik
 
Intro to Functional Reactive Programming In Scala
Intro to Functional Reactive Programming In ScalaIntro to Functional Reactive Programming In Scala
Intro to Functional Reactive Programming In Scala
Diego Alonso
 
Actors and functional_reactive_programming
Actors and functional_reactive_programmingActors and functional_reactive_programming
Actors and functional_reactive_programming
Diego Alonso
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
Sangharsh agarwal
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
M-TEC Computer Education
 
Alp 05
Alp 05Alp 05
Alp 05
gswapnil86
 

What's hot (20)

Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
C program
C programC program
C program
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
C Programming
C ProgrammingC Programming
C Programming
 
C language
C languageC language
C language
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Intro to Functional Reactive Programming In Scala
Intro to Functional Reactive Programming In ScalaIntro to Functional Reactive Programming In Scala
Intro to Functional Reactive Programming In Scala
 
Actors and functional_reactive_programming
Actors and functional_reactive_programmingActors and functional_reactive_programming
Actors and functional_reactive_programming
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Alp 05
Alp 05Alp 05
Alp 05
 

Similar to Special topics in finance lecture 2

R Programming Language
R Programming LanguageR Programming Language
R Programming Language
NareshKarela1
 
1_Introduction.pptx
1_Introduction.pptx1_Introduction.pptx
1_Introduction.pptx
ranapoonam1
 
R basics for MBA Students[1].pptx
R basics for MBA Students[1].pptxR basics for MBA Students[1].pptx
R basics for MBA Students[1].pptx
rajalakshmi5921
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
manikanta361
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
Abishek Purushothaman
 
FULL R PROGRAMMING METERIAL_2.pdf
FULL R PROGRAMMING METERIAL_2.pdfFULL R PROGRAMMING METERIAL_2.pdf
FULL R PROGRAMMING METERIAL_2.pdf
attalurilalitha
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
Unmesh Baile
 
Lecture1
Lecture1Lecture1
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
ArchishaKhandareSS20
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
vikassingh569137
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
Sandeep242951
 
Modeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptModeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.ppt
anshikagoel52
 
Dot Call interface
Dot Call interfaceDot Call interface
Dot Call interface
Hao Chai
 
Lecture_R.ppt
Lecture_R.pptLecture_R.ppt
Lecture_R.ppt
Abebe334138
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
KabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
DrGSakthiGovindaraju
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
attalurilalitha
 
R language
R languageR language
R language
LearningTech
 
Presentation on use of r statistics
Presentation on use of r statisticsPresentation on use of r statistics
Presentation on use of r statistics
Krishna Dhakal
 
美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】
美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】
美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】
mikisato746
 

Similar to Special topics in finance lecture 2 (20)

R Programming Language
R Programming LanguageR Programming Language
R Programming Language
 
1_Introduction.pptx
1_Introduction.pptx1_Introduction.pptx
1_Introduction.pptx
 
R basics for MBA Students[1].pptx
R basics for MBA Students[1].pptxR basics for MBA Students[1].pptx
R basics for MBA Students[1].pptx
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
FULL R PROGRAMMING METERIAL_2.pdf
FULL R PROGRAMMING METERIAL_2.pdfFULL R PROGRAMMING METERIAL_2.pdf
FULL R PROGRAMMING METERIAL_2.pdf
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
 
Lecture1
Lecture1Lecture1
Lecture1
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
 
Modeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptModeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.ppt
 
Dot Call interface
Dot Call interfaceDot Call interface
Dot Call interface
 
Lecture_R.ppt
Lecture_R.pptLecture_R.ppt
Lecture_R.ppt
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R language
R languageR language
R language
 
Presentation on use of r statistics
Presentation on use of r statisticsPresentation on use of r statistics
Presentation on use of r statistics
 
美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】
美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】
美洲杯买球-美洲杯买球在哪个软件买球-美洲杯买球买球软件下载|【​网址​🎉ac55.net🎉​】
 

More from Dr. Muhammad Ali Tirmizi., Ph.D.

Financial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali Tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Financial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmizi
Financial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmiziFinancial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmizi
Financial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmizi
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 14
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 14Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 14
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 14
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 13
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 13Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 13
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 13
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 5
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 5Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 5
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 5
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 4
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 4Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 4
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 4
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 3
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 3Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 3
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 3
Dr. Muhammad Ali Tirmizi., Ph.D.
 
Special topics in finance lec 1
Special topics in finance   lec 1Special topics in finance   lec 1
Special topics in finance lec 1
Dr. Muhammad Ali Tirmizi., Ph.D.
 

More from Dr. Muhammad Ali Tirmizi., Ph.D. (19)

Financial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 14 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 13 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 12 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 11 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 10 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 9 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 8 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 7 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 5 & 6 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 4 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 3 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali TirmiziFinancial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali Tirmizi
Financial Risk Mgt - Lec 2 by Dr. Syed Muhammad Ali Tirmizi
 
Financial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmizi
Financial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmiziFinancial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmizi
Financial Risk Mgt - Lec 1 by dr. syed muhammad ali tirmizi
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 14
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 14Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 14
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 14
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 13
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 13Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 13
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 13
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 5
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 5Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 5
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 5
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 4
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 4Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 4
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 4
 
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 3
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 3Dr. Syed Muhammad Ali Tirmizi - Special topics in finance   lec 3
Dr. Syed Muhammad Ali Tirmizi - Special topics in finance lec 3
 
Special topics in finance lec 1
Special topics in finance   lec 1Special topics in finance   lec 1
Special topics in finance lec 1
 

Recently uploaded

一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
uevausa
 
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
Rebecca Bilbro
 
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
yuvarajkumar334
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
NABLAS株式会社
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
vasanthatpuram
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
22ad0301
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
hqfek
 
Digital Marketing Performance Marketing Sample .pdf
Digital Marketing Performance Marketing  Sample .pdfDigital Marketing Performance Marketing  Sample .pdf
Digital Marketing Performance Marketing Sample .pdf
Vineet
 
How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource ManagerHow To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
Alireza Kamrani
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 
Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024
ElizabethGarrettChri
 
Overview IFM June 2024 Consumer Confidence INDEX Report.pdf
Overview IFM June 2024 Consumer Confidence INDEX Report.pdfOverview IFM June 2024 Consumer Confidence INDEX Report.pdf
Overview IFM June 2024 Consumer Confidence INDEX Report.pdf
nhutnguyen355078
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
tzu5xla
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
eoxhsaa
 
一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理
ugydym
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
actyx
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
lzdvtmy8
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
eudsoh
 
Sid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.pptSid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.ppt
ArshadAyub49
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
Timothy Spann
 

Recently uploaded (20)

一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
 
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
PyData London 2024: Mistakes were made (Dr. Rebecca Bilbro)
 
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
 
Digital Marketing Performance Marketing Sample .pdf
Digital Marketing Performance Marketing  Sample .pdfDigital Marketing Performance Marketing  Sample .pdf
Digital Marketing Performance Marketing Sample .pdf
 
How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource ManagerHow To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 
Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024Open Source Contributions to Postgres: The Basics POSETTE 2024
Open Source Contributions to Postgres: The Basics POSETTE 2024
 
Overview IFM June 2024 Consumer Confidence INDEX Report.pdf
Overview IFM June 2024 Consumer Confidence INDEX Report.pdfOverview IFM June 2024 Consumer Confidence INDEX Report.pdf
Overview IFM June 2024 Consumer Confidence INDEX Report.pdf
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
 
一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理一比一原版南昆士兰大学毕业证如何办理
一比一原版南昆士兰大学毕业证如何办理
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
 
Sid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.pptSid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.ppt
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
 

Special topics in finance lecture 2

  • 1. THE R LANGUAGE FOR STATISTICAL COMPUTING Lecture 2 Dr. Syed Muhammad Ali Tirmizi Chapter No. 2 1
  • 2. 2 INTRODUCTION  R language has its roots at AT&T Bell Laboratories during the 1970s and 1980s in the S language project (Becker, Chambers, and Wilks, 1988).  People think that the S language would not have been designed in the way it was if it had been designed by computer scientists (Morandat, Hill, Osvald, and Vitek, 2012).
  • 3. 3 INTRODUCTION  R is an open source variant of S developed at the University of Auckland by Ross Ihaka and Robert Gentleman, first appearing in 1993 (Ihaka, 1998).  Clearly the recent popularity of R, fueled by its open source availability and the need for statistical and analytical computing tools, shows that the benefits of R far outweigh the negatives.  Overall, R is based upon the vector as a first class item in the language.
  • 4. 4 INTRODUCTION  R shares this attribute with LISP, Scheme, Python, and Matlab.  This and the prevalence of over 4,000 publicly available packages are two of the many strengths of R.  In this course, we will focus on R packages that revolve around financial analytics.
  • 5. 5 GETTING STARTED WITH R  One of the great things about R is how easy it is to install.  In your browser, head to the web site for the Comprehensive R Archive Network (CRAN), http://cran.r-project.org  This website will help you to download and install R software for windows.  Just as a basic test, we can create a vector of prices and plot it with this block of code: x = c(1.3,1.2,1.3,NA,1.4,1.5) plot(x,ylab="EUR prices") is.na(x) [1] FALSE FALSE FALSE TRUE FALSE FALSE
  • 6. 6 GETTING STARTED WITH R  The c() operator creates a vector of elements.  This is the basic vector operator in R.  Note the “not available” (NA) element appearing as the fourth item of the vector.  R’s ability to handle NAs, infinite values (Inf), and not a number (NaN) is one of its many strengths.
  • 7. 7 GETTING STARTED WITH R  A later development is the R Studio GUI available from the web site www.rstudio.com.  R Studio is a commercially developed GUI allowing management of plot windows, variable contents, and better debugging than the basic R interpreter.  R Studio is a second-generation R user interface with integrated code, execution, variable inspection, and plotting windows, and expression completion.
  • 8. 8
  • 9. 9 GETTING STARTED WITH R  Any time a library statement is encountered, R will check that the package is available.  If not, it must be downloaded.  As an example, to download the ggplot2 package, use the following command: update.packages() install.packages("ggplot2",dependencies=TRUE) library(ggplot2)
  • 10. 10 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  For many use cases, R provides a computational statistics platform.  Mathematical functions are readily available. The basic log() function provides a natural logarithm. Of course, executing log() on a vector, x, results in a vector of natural logarithms, y.
  • 11. 11 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  The computation of log() on NA is NA as expected. > #Filter prices: > x[x > 1.3] [1] NA 1.4 1.5 > #Keeps the NA intact: > y <- diff(log(x)) > round(y,3) [1] -0.080 0.080 NA NA 0.069
  • 12. 12 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  In R, not only vectors but also functions are first- class objects. It shares this attribute with the functional languages LISP and Scheme.  Assigning a function to a variable is the usual way to define it. If g is assigned to the function definition, then g(4) will evaluate it and g, without parentheses, will return its definition.
  • 14. 14 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  R has four assignment operators.  The most basic operator is “<-”. This is the one we use in the first assignment in the code block below.  R’s functional nature is so strong that even this can be replaced by the function call assign(“x”,1).
  • 15. 15 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  Over time, because people were used to other languages that use “=” instead, and even though “=” was used to assign parameter values in function calls (g(x, y = 7), for example), it was also made available for assignment in R.  So using “<-” or “=” is now really a matter of preference.
  • 16. 16 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES > x <- 1 > assign("x",2) > x [1] 2 > x = 3 > x [1] 3 > f <-function(x) + { + x = 4 + x + } > f(x) [1] 4 > x [1] 3 RUN THESE CODES
  • 17. 17 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  R’s fourth assignment operator, with two “<”s, is known as the “super-assignment” operator.  Executing it will look outside the current frame for x, which is global to the function f , and assign to that x.  If there is no x in the global environment, it will create one and assign the value to it.
  • 18. 18 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES > #The fourth type is "<<-" > x = 3 > x [1] 3 > f <-function(x) + { + x <<- 4 + x + } > f(x) [1] 4 > x [1] 4 > typeof(f) [1] "closure" > typeof(x) [1] "double" RUN THESE CODES
  • 19. 19 LANGUAGE FEATURES: FUNCTIONS, ASSIGNMENT, ARGUMENTS, AND TYPES  R is dynamically typed so that variables do not have types.  Instead, values have types.  So we can see that the type of a variable is determined by the type of its current value.  The function typeof() can be used to return the type of the value assigned to a variable.  We can see its use in the output block above: typeof(f) is a “closure” for a function while typeof(x) is a “double.”
  • 20. 20 LANGUAGE FEATURES: BINDING AND ARRAYS  Binding scalars or vectors together is one way to return aggregate results from functions.  For binding, cbind() binds items into two columns and rbind() binds items into two rows.  If the two items are scalars then the two operations are equivalent. rep() is a very common function to create a vector of repeated items.  For example, rep(4, 5) == c(4, 4, 4, 4, 4) is TRUE and states to repeat 4 five times.
  • 21. 21 LANGUAGE FEATURES: BINDING AND ARRAYS > #Create two column matrix: > A = cbind(rep(x,length(y)),y) > A y [1,] 4 -0.08004271 [2,] 4 0.08004271 [3,] 4 NA [4,] 4 NA [5,] 4 0.06899287 > B = rbind(rep(x,length(y)),y) > B [,1] [,2] [,3] [,4] [,5] 4.00000000 4.00000000 4 4 4.00000000 y -0.08004271 0.08004271 NA NA 0.06899287 > t(A) == B [,1] [,2] [,3] [,4] [,5] TRUE TRUE TRUE TRUE TRUE y TRUE TRUE NA NA TRUE > sum(t(A) == B) [1] NA RUN THESE CODES
  • 22. 22 ERROR HANDLING  Error handling is an important part of data science, in order to keep erroneous data from making its way into the variables and to keep the dataset as clean as possible.  When calling certain packages, it is common to have errors returned. R has a tryCatch() feature which is implemented as a function.  Example, we use division by zero as the type of error handled.
  • 23. 23 ERROR HANDLING #Exception handling: fh <- 0 tryCatch({ #main block fh <<- file("file1.txt", open="r") }, warning = function(w) { #warning-handler-code print(w) fh <<- NA }, error = function(e) { #error-handler-code print(e) fh <<- NA }, finally = { #cleanup-code }) if(!is.na(fh)) readLines(fh) RUN THESE CODES
  • 24. 24 NUMERIC, STATISTICAL, AND CHARACTER FUNCTIONS  To set the mode of calculations, options(digits = n) sets the number of digits to round to in calculations. #Setting precision: options(digits=10) pi = 3.1415926535897932384626 pi  [1] 3.141592654
  • 25. 25 NUMERIC, STATISTICAL, AND CHARACTER FUNCTIONS  Distributions of random variates are available readily within the language with runif() for the Uniform Distribution, rnorm() for the Normal Distribution, and rbinom() for the Binomial Distribution, to name just three.  Histograms and density plots are also native to the language with hist() and density().
  • 26. 26 NUMERIC, STATISTICAL, AND CHARACTER FUNCTIONS plot(density(rbinom(50,50,1/2)) options(digits=6) set.seed(99) sample(10, replace = TRUE) [1] 6 2 7 10 6 10 7 3 4 2
  • 27. 27 DATA FRAMES AND INPUT–OUTPUT  Data frames are one of R’s more unusual and handy features.  A data frame is a sequence of rows where the columns are heterogeneously typed. A common way of loading data frames is from the Excel .csv files. #Input-ouput: write.csv(d,file="d.txt",row.names=FALSE) e <- read.csv("d.txt",header=TRUE)
  • 28. 28 LISTS  Lists are ordered aggregates like vectors, which are constructed by c(. . .).  However, lists differ from the basic vectors, in that they are recursively formed, using list(. . .). #Lists: c(1,c(1,2),3,"A",c(4,5)) [1] "1" "1" "2" "3" "A" "4" "5" list(1,c(1,2),3,"A",list(4,5))