SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
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!!

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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...
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Kürzlich hochgeladen (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

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