SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
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!!

Contenu connexe

Tendances

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 ShapelessAnatolii Kmetiuk
 
Rattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageRattle Graphical Interface for R Language
Rattle Graphical Interface for R LanguageMajid Abdollahi
 
Kof2008 Itll
Kof2008 ItllKof2008 Itll
Kof2008 Itllujihisa
 
Introduction to array and string
Introduction to array and stringIntroduction to array and string
Introduction to array and stringMuntasirMuhit
 
NTCIR11-Math2-PattaniyilN_poster
NTCIR11-Math2-PattaniyilN_posterNTCIR11-Math2-PattaniyilN_poster
NTCIR11-Math2-PattaniyilN_posterNidhin Pattaniyil
 
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 TreeManishPrajapati78
 
Purely Functional Data Structures
Purely Functional Data StructuresPurely Functional Data Structures
Purely Functional Data StructuresJean-Baptiste Mazon
 
Data science : R Basics Harvard University
Data science : R Basics Harvard UniversityData science : R Basics Harvard University
Data science : R Basics Harvard UniversityMrMoliya
 
The Very ^ 2 Basics of R
The Very ^ 2 Basics of RThe Very ^ 2 Basics of R
The Very ^ 2 Basics of RWinston Chen
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional ProgrammingYuan 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) presentationVedaGayathri1
 
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 KhanDaniyal Khan
 

Tendances (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
 

Similaire à R language, an introduction

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 AnalyticsArchana Gopinath
 
R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming FundamentalsRagia Ibrahim
 
Introduction to R
Introduction to RIntroduction to R
Introduction to RHappy 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, 2011Mandi Walls
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptxkarthikks82
 
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 LearningAmanBhalla14
 
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 BangaloreSatnam 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 LibrariesAndrew 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
 

Similaire à 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...
 

Plus de 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 AppsVenkatesh 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 SuitesVenkatesh 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 ComparisonVenkatesh Prasad Ranganath
 

Plus de 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
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Dernier (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

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!!