SlideShare a Scribd company logo
The R Language
A Hands-on Introduction
Venkatesh-Prasad Ranganath
http://about.me/rvprasad
What is R?
• A dynamical typed programming language
• http://cran.r-project.org/
• Open source and free
• Provides common programming language constructs/features
• Multiple programming paradigms
• Numerous libraries focused on various data-rich topics
• http://cran.r-project.org/web/views/
• Ideal for statistical calculation; lately, the go-to tool for data analysis
• Accompanied by RStudio, a simple and powerful IDE
• http://rstudio.org
Data Types (Modes)
• Numeric
• Character
• Logical (TRUE / FALSE)
• Complex
• Raw (bytes)
Data Structures
• Vectors
• Matrices
• Arrays
• Lists
• Data Frames
• Factors
• Tables
Data Structures: Vectors
• A sequence of objects of the same (atomic) data type
• Creation
• x <- b c [ <- is the assignment operator ]
• y <- seq(5, 9, 2) = c(5, 7, 9)
• y <- 5:7 = c(5, 6, 7) [ m:n is equivalent to seq(m, n, 1) ]
• y <- c(1, 4:6) = c(1, 4, 5, 6) [ no nesting / always flattened ]
• z <- rep(1, 3) = c(1, 1, 1)
Data Structures: Vectors
• Accessing
• x[1] [ 1-based indexing ]
• x[2:3]
• x[c(2,3)] = x[2:3]
• x[-1] [ Negative subscripts imply exclusion ]
• Naming
• names(x) <- [ Makes equivalent to x[1] ]
Data Structures: Vectors
• Operations
• x <- c(5, 6, 7)
• x + 2 = c(7, 8, 9) [ Vectorized operations ]
• x > 5 = c(FALSE, TRUE, TRUE)
• subset(x, x > 5) = c(6, 7)
• which(x > 5) = c(2, 3)
• ifelse(x > 5, NaN, x) = c(5, NaN, NaN)
• sqr <- function (n) { n * n }
• sapply(x,sqr) = c(25 ,36, 49)
• sqr(x) = c(25, 36, 49)
Data Structures: Vectors
• Operations
• x <- c(5, 6, 7)
• any(x > 5) = TRUE [ How about all(x > 5)? ]
• sum(c(1, 2, 3, NA), na.rm = TRUE) = 6 [ Why is na.rm required? ]
• sort(c(7, 6, 5)) = c(5, 6, 7)
• order(c(7, 6, 5)) = ???
• subset(x, x > 5) = c(6, 7)
• head(1:100) = ???
• tail(1:100) = ???
• How is x == c(5, 6, 7) different from identical(x, c(5, 6, 7))?
• Try str(x)
Data Structures: Matrices
• A two dimensional matrix of objects of the same (atomic) data type
• Creation
• y <- matrix(nrow=2, ncol=3) [ empty matrix ]
• y <- matrix(c(1, 2, 3, 4, 5, 6), nrow=2) =
• y <- matrix(c(1, 2, 3, 4, 5, 6), nrow=2, byrow=T) =
• Accessing
• y[1,2] = 2
• y[,2:3] = [ How about y[1,]? ]
• What’s the difference between y[2,] and y[2,, drop=FALSE]?
1 3 5
2 4 6
1 2 3
4 5 6
2 3
5 6
Data Structures: Matrices
• Naming
• rownames() and colnames()
• Operations
• nrow(y) = 2 [ number of rows ]
• ncol(y) = 3 [ number of columns ]
• apply(y, 1, sum) = c(6, 15) [ apply sum to each row ]
• apply(y, 2, sum) = c(5, 7, 9) [ apply sum to each column ]
• t(y) = [ transpose a matrix ]1 4
2 5
3 6
Data Structures: Matrices
• Operations
• rbind(y, c(7, 8, 9)) =
• cbind(y, c(7, 8)) =
• Try str(y)
1 2 3
4 5 6
7 8 9
1 2 3 7
4 5 6 8
Data Structures: Matrices
• What will this yield?
m <- matrix(nrow=4, ncol=4)
m <- ifelse(row(m) == col(m), 1, 0.3)
Data Structures: Lists
• A sequence of objects (of possibly different data types)
• Creation
• k <- list(c(1, 2, 3),
• l <- [ f1 and f2 are tags ]
• Accessing
• k[2:3]
• k[[2]] [ How about k[2]? ]
• l$f1 = c(1, 2, 3) [ Is it same as l[1] or l[[1]]? ]
Data Structures: Lists
• Naming
• names(k) <-
• Operations
• lapply(list(1:2, 9:10), sum) = list(3, 19)
• sapply(list(1:2, 9:10), sum) = c(3, 19)
• l$f1 <- NULL = ???
• str(l) = ???
Data Structures: Data Frames
• A two dimensional matrix of objects where different columns can be of
different types.
• Creation
• x <- data.frame jill
• Accessing
• x$names jill [ How about x[[1]]? ]
• x[1] = ???
• x[c(1,2)] = ???
• x[1,] = ???
• x[,1] = ???
Data Structures: Data Frames
• Naming
• rownames() and colnames()
• Operations
• x[x$age > 5,] = data.frame jill ))
• subset(x, age > 5) = ???
• apply(x, 1, sum) = ???
• y <- data.frame(1:3, 5:7)
• apply(y, 1, mean) = ???
• lapply(y, mean) = ???
• sapply(y, mean) = ???
• Try str(y)
Factors (and Tables)
• Type for categorical/nominal values.
• Example
• xf <- factor(c(1:3, 2, 4:5))
• Try xf and str(xf)
• Operations
• table(xf) = ???
• with(mtcars, split(mpg, cyl)) = ???
• with(mtcars, tapply(mpg, cyl, mean)) = ???
• by(mtcars, mtcars$cyl, function(m) { median(m$mpg) } = ???
• aggregate(mtcars, list(mtcars$cyl), median) = ???
• You can use cut to bin values and create factors. Try it.
Basic Graphs
• with(mtcars, boxplot(mpg))
• hist(mtcars$mpg)
• with(mtcars, plot(hp, mpg))
• dotchart(VADeaths)
• Try plot(aggregate(mtcars, list(mtcars$cyl), median))
You can get the list of datasets via ls package.datasets
Stats 101 using R
• mean
• median
• What about mode?
• fivenum
• quantile
• sd
• var
• cov
• cor
Data Exploration using R
Let’s get out hands dirty!!

More Related Content

What's hot

Motivation and Mechanics behind some aspects of Shapeless
Motivation and Mechanics behind some aspects of ShapelessMotivation and Mechanics behind some aspects of Shapeless
Motivation and Mechanics behind some aspects of Shapeless
Anatolii Kmetiuk
 
Rattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageRattle Graphical Interface for R Language
Rattle Graphical Interface for R Language
Majid Abdollahi
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
Ismail Seyrik
 
Kof2008 Itll
Kof2008 ItllKof2008 Itll
Kof2008 Itll
ujihisa
 
Introduction to array and string
Introduction to array and stringIntroduction to array and string
Introduction to array and string
MuntasirMuhit
 
NTCIR11-Math2-PattaniyilN_poster
NTCIR11-Math2-PattaniyilN_posterNTCIR11-Math2-PattaniyilN_poster
NTCIR11-Math2-PattaniyilN_posterNidhin Pattaniyil
 
R program
R programR program
R program
genegeek
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Purely Functional Data Structures
Purely Functional Data StructuresPurely Functional Data Structures
Purely Functional Data Structures
Jean-Baptiste Mazon
 
Data science : R Basics Harvard University
Data science : R Basics Harvard UniversityData science : R Basics Harvard University
Data science : R Basics Harvard University
MrMoliya
 
Type-Aware Entity Retrieval
Type-Aware Entity RetrievalType-Aware Entity Retrieval
Type-Aware Entity Retrieval
Darío Garigliotti
 
The Very ^ 2 Basics of R
The Very ^ 2 Basics of RThe Very ^ 2 Basics of R
The Very ^ 2 Basics of R
Winston Chen
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
Yuan Wang
 
Wrokflow programming and provenance query model
Wrokflow programming and provenance query model  Wrokflow programming and provenance query model
Wrokflow programming and provenance query model
Rayhan Ferdous
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
Trupti Agrawal
 
Python data structures (Lists and tuples) presentation
Python data structures (Lists and tuples) presentationPython data structures (Lists and tuples) presentation
Python data structures (Lists and tuples) presentation
VedaGayathri1
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
R statistics with mongo db
R statistics with mongo dbR statistics with mongo db
R statistics with mongo dbMongoDB
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
Daniyal Khan
 

What's hot (20)

Motivation and Mechanics behind some aspects of Shapeless
Motivation and Mechanics behind some aspects of ShapelessMotivation and Mechanics behind some aspects of Shapeless
Motivation and Mechanics behind some aspects of Shapeless
 
Rattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageRattle Graphical Interface for R Language
Rattle Graphical Interface for R Language
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Kof2008 Itll
Kof2008 ItllKof2008 Itll
Kof2008 Itll
 
702 present
702 present702 present
702 present
 
Introduction to array and string
Introduction to array and stringIntroduction to array and string
Introduction to array and string
 
NTCIR11-Math2-PattaniyilN_poster
NTCIR11-Math2-PattaniyilN_posterNTCIR11-Math2-PattaniyilN_poster
NTCIR11-Math2-PattaniyilN_poster
 
R program
R programR program
R program
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Purely Functional Data Structures
Purely Functional Data StructuresPurely Functional Data Structures
Purely Functional Data Structures
 
Data science : R Basics Harvard University
Data science : R Basics Harvard UniversityData science : R Basics Harvard University
Data science : R Basics Harvard University
 
Type-Aware Entity Retrieval
Type-Aware Entity RetrievalType-Aware Entity Retrieval
Type-Aware Entity Retrieval
 
The Very ^ 2 Basics of R
The Very ^ 2 Basics of RThe Very ^ 2 Basics of R
The Very ^ 2 Basics of R
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Wrokflow programming and provenance query model
Wrokflow programming and provenance query model  Wrokflow programming and provenance query model
Wrokflow programming and provenance query model
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Python data structures (Lists and tuples) presentation
Python data structures (Lists and tuples) presentationPython data structures (Lists and tuples) presentation
Python data structures (Lists and tuples) presentation
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
R statistics with mongo db
R statistics with mongo dbR statistics with mongo db
R statistics with mongo db
 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
 

Similar to R language, an introduction

R language introduction
R language introductionR language introduction
R language introduction
Shashwat Shriparv
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
Josh Doyle
 
R training3
R training3R training3
R training3
Hellen Gakuruh
 
Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
Archana Gopinath
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
Massimiliano Ruocco
 
R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming Fundamentals
Ragia Ibrahim
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Happy Garg
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
Mandi Walls
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptx
karthikks82
 
Language R
Language RLanguage R
Language R
Girish Khanzode
 
Ch1
Ch1Ch1
R programming by ganesh kavhar
R programming by ganesh kavharR programming by ganesh kavhar
R programming by ganesh kavhar
Savitribai Phule Pune University
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to pythonActiveState
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
AmanBhalla14
 
SMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachSMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachReza Rahimi
 
India software developers conference 2013 Bangalore
India software developers conference 2013 BangaloreIndia software developers conference 2013 Bangalore
India software developers conference 2013 Bangalore
Satnam Singh
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Andrew Ferlitsch
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
HendraPurnama31
 

Similar to R language, an introduction (20)

R language introduction
R language introductionR language introduction
R language introduction
 
R
RR
R
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
R training3
R training3R training3
R training3
 
Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming Fundamentals
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptx
 
Language R
Language RLanguage R
Language R
 
Ch1
Ch1Ch1
Ch1
 
R programming by ganesh kavhar
R programming by ganesh kavharR programming by ganesh kavhar
R programming by ganesh kavhar
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
SMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachSMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning Approach
 
India software developers conference 2013 Bangalore
India software developers conference 2013 BangaloreIndia software developers conference 2013 Bangalore
India software developers conference 2013 Bangalore
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
 

More from Venkatesh Prasad Ranganath

SeMA: A Design Methodology for Building Secure Android Apps
SeMA: A Design Methodology for Building Secure Android AppsSeMA: A Design Methodology for Building Secure Android Apps
SeMA: A Design Methodology for Building Secure Android Apps
Venkatesh Prasad Ranganath
 
Are free Android app security analysis tools effective in detecting known vul...
Are free Android app security analysis tools effective in detecting known vul...Are free Android app security analysis tools effective in detecting known vul...
Are free Android app security analysis tools effective in detecting known vul...
Venkatesh Prasad Ranganath
 
Benchpress: Analyzing Android App Vulnerability Benchmark Suites
Benchpress:  Analyzing Android App Vulnerability Benchmark SuitesBenchpress:  Analyzing Android App Vulnerability Benchmark Suites
Benchpress: Analyzing Android App Vulnerability Benchmark Suites
Venkatesh Prasad Ranganath
 
Why do Users kill HPC Jobs?
Why do Users kill HPC Jobs?Why do Users kill HPC Jobs?
Why do Users kill HPC Jobs?
Venkatesh Prasad Ranganath
 
Behavior Driven Development [10] - Software Testing Techniques (CIS640)
Behavior Driven Development [10] - Software Testing Techniques (CIS640)Behavior Driven Development [10] - Software Testing Techniques (CIS640)
Behavior Driven Development [10] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Code Coverage [9] - Software Testing Techniques (CIS640)
Code Coverage [9] - Software Testing Techniques (CIS640)Code Coverage [9] - Software Testing Techniques (CIS640)
Code Coverage [9] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Boundary Value Testing [7] - Software Testing Techniques (CIS640)
Boundary Value Testing [7] - Software Testing Techniques (CIS640)Boundary Value Testing [7] - Software Testing Techniques (CIS640)
Boundary Value Testing [7] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Intro to Python3 [2] - Software Testing Techniques (CIS640)
Intro to Python3 [2] - Software Testing Techniques (CIS640)Intro to Python3 [2] - Software Testing Techniques (CIS640)
Intro to Python3 [2] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Unit testing [4] - Software Testing Techniques (CIS640)
Unit testing [4] - Software Testing Techniques (CIS640)Unit testing [4] - Software Testing Techniques (CIS640)
Unit testing [4] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Introduction [1] - Software Testing Techniques (CIS640)
Introduction [1] - Software Testing Techniques (CIS640)Introduction [1] - Software Testing Techniques (CIS640)
Introduction [1] - Software Testing Techniques (CIS640)
Venkatesh Prasad Ranganath
 
Compatibility Testing using Patterns-based Trace Comparison
Compatibility Testing using Patterns-based Trace ComparisonCompatibility Testing using Patterns-based Trace Comparison
Compatibility Testing using Patterns-based Trace Comparison
Venkatesh Prasad Ranganath
 
My flings with data analysis
My flings with data analysisMy flings with data analysis
My flings with data analysis
Venkatesh Prasad Ranganath
 
Data analytics, a (short) tour
Data analytics, a (short) tourData analytics, a (short) tour
Data analytics, a (short) tour
Venkatesh Prasad Ranganath
 
Pattern-based Features
Pattern-based FeaturesPattern-based Features
Pattern-based Features
Venkatesh Prasad Ranganath
 

More from Venkatesh Prasad Ranganath (17)

SeMA: A Design Methodology for Building Secure Android Apps
SeMA: A Design Methodology for Building Secure Android AppsSeMA: A Design Methodology for Building Secure Android Apps
SeMA: A Design Methodology for Building Secure Android Apps
 
Are free Android app security analysis tools effective in detecting known vul...
Are free Android app security analysis tools effective in detecting known vul...Are free Android app security analysis tools effective in detecting known vul...
Are free Android app security analysis tools effective in detecting known vul...
 
Benchpress: Analyzing Android App Vulnerability Benchmark Suites
Benchpress:  Analyzing Android App Vulnerability Benchmark SuitesBenchpress:  Analyzing Android App Vulnerability Benchmark Suites
Benchpress: Analyzing Android App Vulnerability Benchmark Suites
 
Why do Users kill HPC Jobs?
Why do Users kill HPC Jobs?Why do Users kill HPC Jobs?
Why do Users kill HPC Jobs?
 
Behavior Driven Development [10] - Software Testing Techniques (CIS640)
Behavior Driven Development [10] - Software Testing Techniques (CIS640)Behavior Driven Development [10] - Software Testing Techniques (CIS640)
Behavior Driven Development [10] - Software Testing Techniques (CIS640)
 
Code Coverage [9] - Software Testing Techniques (CIS640)
Code Coverage [9] - Software Testing Techniques (CIS640)Code Coverage [9] - Software Testing Techniques (CIS640)
Code Coverage [9] - Software Testing Techniques (CIS640)
 
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
Equivalence Class Testing [8] - Software Testing Techniques (CIS640)
 
Boundary Value Testing [7] - Software Testing Techniques (CIS640)
Boundary Value Testing [7] - Software Testing Techniques (CIS640)Boundary Value Testing [7] - Software Testing Techniques (CIS640)
Boundary Value Testing [7] - Software Testing Techniques (CIS640)
 
Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)
 
Intro to Python3 [2] - Software Testing Techniques (CIS640)
Intro to Python3 [2] - Software Testing Techniques (CIS640)Intro to Python3 [2] - Software Testing Techniques (CIS640)
Intro to Python3 [2] - Software Testing Techniques (CIS640)
 
Unit testing [4] - Software Testing Techniques (CIS640)
Unit testing [4] - Software Testing Techniques (CIS640)Unit testing [4] - Software Testing Techniques (CIS640)
Unit testing [4] - Software Testing Techniques (CIS640)
 
Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)Testing concepts [3] - Software Testing Techniques (CIS640)
Testing concepts [3] - Software Testing Techniques (CIS640)
 
Introduction [1] - Software Testing Techniques (CIS640)
Introduction [1] - Software Testing Techniques (CIS640)Introduction [1] - Software Testing Techniques (CIS640)
Introduction [1] - Software Testing Techniques (CIS640)
 
Compatibility Testing using Patterns-based Trace Comparison
Compatibility Testing using Patterns-based Trace ComparisonCompatibility Testing using Patterns-based Trace Comparison
Compatibility Testing using Patterns-based Trace Comparison
 
My flings with data analysis
My flings with data analysisMy flings with data analysis
My flings with data analysis
 
Data analytics, a (short) tour
Data analytics, a (short) tourData analytics, a (short) tour
Data analytics, a (short) tour
 
Pattern-based Features
Pattern-based FeaturesPattern-based Features
Pattern-based Features
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 

R language, an introduction

  • 1. The R Language A Hands-on Introduction Venkatesh-Prasad Ranganath http://about.me/rvprasad
  • 2. What is R? • A dynamical typed programming language • http://cran.r-project.org/ • Open source and free • Provides common programming language constructs/features • Multiple programming paradigms • Numerous libraries focused on various data-rich topics • http://cran.r-project.org/web/views/ • Ideal for statistical calculation; lately, the go-to tool for data analysis • Accompanied by RStudio, a simple and powerful IDE • http://rstudio.org
  • 3. Data Types (Modes) • Numeric • Character • Logical (TRUE / FALSE) • Complex • Raw (bytes)
  • 4. Data Structures • Vectors • Matrices • Arrays • Lists • Data Frames • Factors • Tables
  • 5. Data Structures: Vectors • A sequence of objects of the same (atomic) data type • Creation • x <- b c [ <- is the assignment operator ] • y <- seq(5, 9, 2) = c(5, 7, 9) • y <- 5:7 = c(5, 6, 7) [ m:n is equivalent to seq(m, n, 1) ] • y <- c(1, 4:6) = c(1, 4, 5, 6) [ no nesting / always flattened ] • z <- rep(1, 3) = c(1, 1, 1)
  • 6. Data Structures: Vectors • Accessing • x[1] [ 1-based indexing ] • x[2:3] • x[c(2,3)] = x[2:3] • x[-1] [ Negative subscripts imply exclusion ] • Naming • names(x) <- [ Makes equivalent to x[1] ]
  • 7. Data Structures: Vectors • Operations • x <- c(5, 6, 7) • x + 2 = c(7, 8, 9) [ Vectorized operations ] • x > 5 = c(FALSE, TRUE, TRUE) • subset(x, x > 5) = c(6, 7) • which(x > 5) = c(2, 3) • ifelse(x > 5, NaN, x) = c(5, NaN, NaN) • sqr <- function (n) { n * n } • sapply(x,sqr) = c(25 ,36, 49) • sqr(x) = c(25, 36, 49)
  • 8. Data Structures: Vectors • Operations • x <- c(5, 6, 7) • any(x > 5) = TRUE [ How about all(x > 5)? ] • sum(c(1, 2, 3, NA), na.rm = TRUE) = 6 [ Why is na.rm required? ] • sort(c(7, 6, 5)) = c(5, 6, 7) • order(c(7, 6, 5)) = ??? • subset(x, x > 5) = c(6, 7) • head(1:100) = ??? • tail(1:100) = ??? • How is x == c(5, 6, 7) different from identical(x, c(5, 6, 7))? • Try str(x)
  • 9. Data Structures: Matrices • A two dimensional matrix of objects of the same (atomic) data type • Creation • y <- matrix(nrow=2, ncol=3) [ empty matrix ] • y <- matrix(c(1, 2, 3, 4, 5, 6), nrow=2) = • y <- matrix(c(1, 2, 3, 4, 5, 6), nrow=2, byrow=T) = • Accessing • y[1,2] = 2 • y[,2:3] = [ How about y[1,]? ] • What’s the difference between y[2,] and y[2,, drop=FALSE]? 1 3 5 2 4 6 1 2 3 4 5 6 2 3 5 6
  • 10. Data Structures: Matrices • Naming • rownames() and colnames() • Operations • nrow(y) = 2 [ number of rows ] • ncol(y) = 3 [ number of columns ] • apply(y, 1, sum) = c(6, 15) [ apply sum to each row ] • apply(y, 2, sum) = c(5, 7, 9) [ apply sum to each column ] • t(y) = [ transpose a matrix ]1 4 2 5 3 6
  • 11. Data Structures: Matrices • Operations • rbind(y, c(7, 8, 9)) = • cbind(y, c(7, 8)) = • Try str(y) 1 2 3 4 5 6 7 8 9 1 2 3 7 4 5 6 8
  • 12. Data Structures: Matrices • What will this yield? m <- matrix(nrow=4, ncol=4) m <- ifelse(row(m) == col(m), 1, 0.3)
  • 13. Data Structures: Lists • A sequence of objects (of possibly different data types) • Creation • k <- list(c(1, 2, 3), • l <- [ f1 and f2 are tags ] • Accessing • k[2:3] • k[[2]] [ How about k[2]? ] • l$f1 = c(1, 2, 3) [ Is it same as l[1] or l[[1]]? ]
  • 14. Data Structures: Lists • Naming • names(k) <- • Operations • lapply(list(1:2, 9:10), sum) = list(3, 19) • sapply(list(1:2, 9:10), sum) = c(3, 19) • l$f1 <- NULL = ??? • str(l) = ???
  • 15. Data Structures: Data Frames • A two dimensional matrix of objects where different columns can be of different types. • Creation • x <- data.frame jill • Accessing • x$names jill [ How about x[[1]]? ] • x[1] = ??? • x[c(1,2)] = ??? • x[1,] = ??? • x[,1] = ???
  • 16. Data Structures: Data Frames • Naming • rownames() and colnames() • Operations • x[x$age > 5,] = data.frame jill )) • subset(x, age > 5) = ??? • apply(x, 1, sum) = ??? • y <- data.frame(1:3, 5:7) • apply(y, 1, mean) = ??? • lapply(y, mean) = ??? • sapply(y, mean) = ??? • Try str(y)
  • 17. Factors (and Tables) • Type for categorical/nominal values. • Example • xf <- factor(c(1:3, 2, 4:5)) • Try xf and str(xf) • Operations • table(xf) = ??? • with(mtcars, split(mpg, cyl)) = ??? • with(mtcars, tapply(mpg, cyl, mean)) = ??? • by(mtcars, mtcars$cyl, function(m) { median(m$mpg) } = ??? • aggregate(mtcars, list(mtcars$cyl), median) = ??? • You can use cut to bin values and create factors. Try it.
  • 18. Basic Graphs • with(mtcars, boxplot(mpg)) • hist(mtcars$mpg) • with(mtcars, plot(hp, mpg)) • dotchart(VADeaths) • Try plot(aggregate(mtcars, list(mtcars$cyl), median)) You can get the list of datasets via ls package.datasets
  • 19. Stats 101 using R • mean • median • What about mode? • fivenum • quantile • sd • var • cov • cor
  • 20. Data Exploration using R Let’s get out hands dirty!!