SlideShare a Scribd company logo
Data available in R
> data()
> data("AirPassengers")
> head(AirPassengers)
[1] 112 118 132 129 121 135
> tail(AirPassengers)
[1] 622 606 508 461 390 432
> str(AirPassengers)
Time-Series [1:144] from 1949 to 1961: 112 118 132 129 121 135 148 148
136 119 ...
> class(AirPassengers)
[1] "ts"
> help(ts)

• The command data() loads data-sets available in R
• head() and tail() command displays first few or last few
values
• str() shows the structure of an R object
• class() shows the class of an R object
• What does “ts” stand for?
Try runif() and plot() commands ….
runif(10)
[1] 0.14350413 0.54293576 0.62881627 0.30278850 0.28030129 0.03784996
0.49483957
[8] 0.23571517 0.40072956 0.20327478
> plot(runif(10))

The runif()
command generates
U(0,1)10 random
numbers between 0
and 1.
These numbers have
been plotted by the
plot() function.
A dataset in R: iris
> head(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1
5.1
3.5
1.4
0.2 setosa
2
4.9
3.0
1.4
0.2 setosa
3
4.7
3.2
1.3
0.2 setosa
4
4.6
3.1
1.5
0.2 setosa
5
5.0
3.6
1.4
0.2 setosa
6
5.4
3.9
1.7
0.4 setosa
> tail(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width
145
6.7
3.3
5.7
2.5
146
6.7
3.0
5.2
2.3
147
6.3
2.5
5.0
1.9
148
6.5
3.0
5.2
2.0
149
6.2
3.4
5.4
2.3
150
5.9
3.0
5.1
1.8

Species
virginica
virginica
virginica
virginica
virginica
virginica

The iris dataset contains measurement of 150 flowers, 50
each from 3 species : iris setosa, versicolor and virginica.
Data frame in R: iris
> str(iris)
'data.frame':
150 obs. of 5 variables:
$ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
$ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
$ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
$ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
$ Species
: Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1
1 1 1 1 1 ...
> class(iris)
[1] "data.frame"

• As you see, iris is not a simple vector but a composite
“data frame” object made up of several component
vectors as you can see in the output of class(iris)
• You can think of a data frame as a matrix-like object
- each row for each observational unit (here, a flower)
- each column for each measurement made on the unit
• But the str() function gives you more concise description
on iris.
Use of $ operator: iris
> iris$Sepal.Length
[1] 5.1 4.9 4.7 4.6
5.7 5.1
[21] 5.4 5.1 4.6 5.1
4.4 5.1
[41] 5.0 4.5 4.4 5.0
6.6 5.2
[61] 5.0 5.9 6.0 6.1
6.0 5.7
[81] 5.5 5.5 5.8 6.0
5.1 5.7
[101] 6.3 5.8 7.1 6.3
7.7 6.0
[121] 6.9 5.6 7.7 6.3
6.0 6.9
[141] 6.7 6.9 5.8 6.8

5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4 5.1
4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5 4.9 5.0 5.5 4.9
5.1 4.8 5.1 4.6 5.3 5.0 7.0 6.4 6.9 5.5 6.5 5.7 6.3 4.9
5.6 6.7 5.6 5.8 6.2 5.6 5.9 6.1 6.3 6.1 6.4 6.6 6.8 6.7
5.4 6.0 6.7 6.3 5.6 5.5 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2
6.5 7.6 4.9 7.3 6.7 7.2 6.5 6.4 6.8 5.7 5.8 6.4 6.5 7.7
6.7 7.2 6.2 6.1 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7 6.3 6.4
6.7 6.7 6.3 6.5 6.2 5.9

Note that $-operator extracts individual components of a data
frame.
Try summary() and IQR() commands on iris$Sepal.Length
and study the data
summary() command: iris
> summary(iris$Sepal.Length)
Min. 1st Qu. Median
Mean 3rd Qu.
Max.
4.300
5.100
5.800
5.843
6.400
7.900
> summary(iris$Species)
setosa versicolor virginica
50
50
50
> summary(iris)
Sepal.Length
Sepal.Width
Petal.Length
Min.
:4.300
Min.
:2.000
Min.
:1.000
1st Qu.:5.100
1st Qu.:2.800
1st Qu.:1.600
Median :5.800
Median :3.000
Median :4.350
Mean
:5.843
Mean
:3.057
Mean
:3.758
3rd Qu.:6.400
3rd Qu.:3.300
3rd Qu.:5.100
Max.
:7.900
Max.
:4.400
Max.
:6.900

Petal.Width
Min.
:0.100
1st Qu.:0.300
Median :1.300
Mean
:1.199
3rd Qu.:1.800
Max.
:2.500

Species
setosa
:50
versicolor:50
virginica :50

• Note the different output formats of using summary()
• Species is summarized (by frequency distribution) as it is a
categorical variable
• The entire data frame iris is summarized by combining the
summaries of its components
class() command: iris
> class(iris$Sepal.Length)
[1] "numeric"
> class(iris$Species)
[1] "factor"
> class(iris)
[1] "data.frame"

• Note that each R object has a class (“numeric”, “factor” etc.)
• summary() is referred to as a generic function
• When summary() is applied, R figures out the appropriate
method and calls it
More on summary() command
> methods(summary)
[1] summary.aov
[4] summary.connection
[7] summary.default
[10] summary.glm
[13] summary.loess*
[16] summary.mlm
[19] summary.PDF_Dictionary*
[22] summary.POSIXlt
[25] summary.princomp*
[28] summary.stepfun
[31] summary.tukeysmooth*

summary.aovlist
summary.data.frame
summary.ecdf*
summary.infl
summary.manova
summary.nls*
summary.PDF_Stream*
summary.ppr*
summary.srcfile
summary.stl*

summary.aspell*
summary.Date
summary.factor
summary.lm
summary.matrix
summary.packageStatus*
summary.POSIXct
summary.prcomp*
summary.srcref
summary.table

Non-visible functions are asterisked

• Objects of class “factor” are handled by summary.factor()
• “data.frame”s are handled by summary.data.frame()
• Numeric vectors are handled by summary.default()
Try the following ….

•
•
•
•
•
•
•
•
•

attach() and detach() with iris
xx <- 1:12 and then dim(xx) <- c(3,4)
apply nrow(xx) and ncol(xx)
dim(xx) <- c(2,2,3)
yy <- matrix(1:12, nrows=3, byrow=TRUE
rownames(yy) <- LETTERS[1:3]
use colnames()
zz <- cbind(A=1:4, B=5:8, C=9:12)
rbind(zz,0)

More Related Content

What's hot (16)

PPT
My sql presentation
Nikhil Jain
 
PDF
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Plotly
 
PPTX
Build a compiler in 2hrs - NCrafts Paris 2015
Phillip Trelford
 
PDF
Data Exploration and Visualization with R
Yanchang Zhao
 
PDF
Array vs set in JavaScript
Ideas2IT Technologies
 
PDF
Quick reference for Grafana
Rajkumar Asohan, PMP
 
PDF
Palestra sobre Collections com Python
pugpe
 
PDF
How fast ist it really? Benchmarking in practice
Tobias Pfeiffer
 
PDF
Implementing pseudo-keywords through Functional Programing
Vincent Pradeilles
 
PPTX
Intro to my sql
Alamgir Bhuyan
 
RTF
Seistech SQL code
Simon Hoyle
 
PPTX
Lecture5 my sql statements by okello erick
okelloerick
 
PPT
Intro to my sql
MusTufa Nullwala
 
PDF
Python Usage (5-minute-summary)
Ohgyun Ahn
 
PDF
PHP 101
Muhammad Hijazi
 
PPT
Intro to my sql
Minhaj Kazi
 
My sql presentation
Nikhil Jain
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Plotly
 
Build a compiler in 2hrs - NCrafts Paris 2015
Phillip Trelford
 
Data Exploration and Visualization with R
Yanchang Zhao
 
Array vs set in JavaScript
Ideas2IT Technologies
 
Quick reference for Grafana
Rajkumar Asohan, PMP
 
Palestra sobre Collections com Python
pugpe
 
How fast ist it really? Benchmarking in practice
Tobias Pfeiffer
 
Implementing pseudo-keywords through Functional Programing
Vincent Pradeilles
 
Intro to my sql
Alamgir Bhuyan
 
Seistech SQL code
Simon Hoyle
 
Lecture5 my sql statements by okello erick
okelloerick
 
Intro to my sql
MusTufa Nullwala
 
Python Usage (5-minute-summary)
Ohgyun Ahn
 
PHP 101
Muhammad Hijazi
 
Intro to my sql
Minhaj Kazi
 

Viewers also liked (8)

PPTX
(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
Sovon Vogelonderzoek
 
PDF
If clause
Kruthai Kidsdee
 
ODP
The Loch Ness Monter
e117024a
 
PDF
画像を使ったバナー作成【実践編】
ec-campus
 
PDF
HTML(5) and CSS(3) for beginners - I
vincentleeuwen
 
PDF
Cours animation et multimédia:
العجمي الشبل
 
PPTX
Statr sessions 4 to 6
Ruru Chowdhury
 
PPT
Statistics
pikuoec
 
(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
Sovon Vogelonderzoek
 
If clause
Kruthai Kidsdee
 
The Loch Ness Monter
e117024a
 
画像を使ったバナー作成【実践編】
ec-campus
 
HTML(5) and CSS(3) for beginners - I
vincentleeuwen
 
Cours animation et multimédia:
العجمي الشبل
 
Statr sessions 4 to 6
Ruru Chowdhury
 
Statistics
pikuoec
 
Ad

Similar to R part iii (20)

PDF
RDataMining slides-data-exploration-visualisation
Yanchang Zhao
 
PDF
01_introduction_lab.pdf
zehiwot hone
 
PPTX
Descriptive Statistics in R.pptx
Ramakrishna Reddy Bijjam
 
DOCX
Summerization notes for descriptive statistics using r
Ashwini Mathur
 
PDF
Iris data analysis example in R
Duyen Do
 
PDF
Irisdataanalysiswithr 140801203600-phpapp02
Pawan Pandey
 
PDF
R programming & Machine Learning
AmanBhalla14
 
PDF
Data Wrangling with dplyr and tidyr Cheat Sheet
Dr. Volkan OBAN
 
PPTX
MODULE 5- EDA.pptx
nikshaikh786
 
PDF
Table of Useful R commands.
Dr. Volkan OBAN
 
PPTX
R language tutorial
David Chiu
 
PDF
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Paul Richards
 
PDF
Machine Learning in R
Alexandros Karatzoglou
 
PDF
TAO Fayan_Report on Top 10 data mining algorithms applications with R
Fayan TAO
 
PDF
R Introduction
Sangeetha S
 
PDF
20170509 rand db_lesugent
Prof. Wim Van Criekinge
 
PPTX
Create a Powerpoint using R software and ReporteRs package
kassambara
 
PPTX
2015-10-23_wim_davis_r_slides.pptx on consumer
tirlukachaitanya
 
PDF
Case Study: Prediction on Iris Dataset Using KNN Algorithm
IRJET Journal
 
PDF
Short Reference Card for R users.
Dr. Volkan OBAN
 
RDataMining slides-data-exploration-visualisation
Yanchang Zhao
 
01_introduction_lab.pdf
zehiwot hone
 
Descriptive Statistics in R.pptx
Ramakrishna Reddy Bijjam
 
Summerization notes for descriptive statistics using r
Ashwini Mathur
 
Iris data analysis example in R
Duyen Do
 
Irisdataanalysiswithr 140801203600-phpapp02
Pawan Pandey
 
R programming & Machine Learning
AmanBhalla14
 
Data Wrangling with dplyr and tidyr Cheat Sheet
Dr. Volkan OBAN
 
MODULE 5- EDA.pptx
nikshaikh786
 
Table of Useful R commands.
Dr. Volkan OBAN
 
R language tutorial
David Chiu
 
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Paul Richards
 
Machine Learning in R
Alexandros Karatzoglou
 
TAO Fayan_Report on Top 10 data mining algorithms applications with R
Fayan TAO
 
R Introduction
Sangeetha S
 
20170509 rand db_lesugent
Prof. Wim Van Criekinge
 
Create a Powerpoint using R software and ReporteRs package
kassambara
 
2015-10-23_wim_davis_r_slides.pptx on consumer
tirlukachaitanya
 
Case Study: Prediction on Iris Dataset Using KNN Algorithm
IRJET Journal
 
Short Reference Card for R users.
Dr. Volkan OBAN
 
Ad

More from Ruru Chowdhury (20)

PPTX
The One With The Wizards and Dragons. Prelims
Ruru Chowdhury
 
PPTX
The One With The Wizards and Dragons. Finals
Ruru Chowdhury
 
PPTX
Statr session 25 and 26
Ruru Chowdhury
 
PPTX
Statr session 23 and 24
Ruru Chowdhury
 
PPTX
Statr session 21 and 22
Ruru Chowdhury
 
PPTX
Statr session 19 and 20
Ruru Chowdhury
 
PPTX
Statr session 17 and 18
Ruru Chowdhury
 
PPTX
Statr session 17 and 18 (ASTR)
Ruru Chowdhury
 
PPTX
Statr session 15 and 16
Ruru Chowdhury
 
PPTX
Statr session14, Jan 11
Ruru Chowdhury
 
PPTX
JM Statr session 13, Jan 11
Ruru Chowdhury
 
PPTX
Statr sessions 11 to 12
Ruru Chowdhury
 
PDF
Nosql part3
Ruru Chowdhury
 
PDF
Nosql part1 8th December
Ruru Chowdhury
 
PDF
Nosql part 2
Ruru Chowdhury
 
PPTX
Statr sessions 9 to 10
Ruru Chowdhury
 
PPTX
R part II
Ruru Chowdhury
 
PPTX
Statr sessions 7 to 8
Ruru Chowdhury
 
PPTX
R part I
Ruru Chowdhury
 
PPTX
Statistics with R
Ruru Chowdhury
 
The One With The Wizards and Dragons. Prelims
Ruru Chowdhury
 
The One With The Wizards and Dragons. Finals
Ruru Chowdhury
 
Statr session 25 and 26
Ruru Chowdhury
 
Statr session 23 and 24
Ruru Chowdhury
 
Statr session 21 and 22
Ruru Chowdhury
 
Statr session 19 and 20
Ruru Chowdhury
 
Statr session 17 and 18
Ruru Chowdhury
 
Statr session 17 and 18 (ASTR)
Ruru Chowdhury
 
Statr session 15 and 16
Ruru Chowdhury
 
Statr session14, Jan 11
Ruru Chowdhury
 
JM Statr session 13, Jan 11
Ruru Chowdhury
 
Statr sessions 11 to 12
Ruru Chowdhury
 
Nosql part3
Ruru Chowdhury
 
Nosql part1 8th December
Ruru Chowdhury
 
Nosql part 2
Ruru Chowdhury
 
Statr sessions 9 to 10
Ruru Chowdhury
 
R part II
Ruru Chowdhury
 
Statr sessions 7 to 8
Ruru Chowdhury
 
R part I
Ruru Chowdhury
 
Statistics with R
Ruru Chowdhury
 

Recently uploaded (20)

PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
national medicinal plants board mpharm.pptx
SHAHEEN SHABBIR
 
PPTX
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
PPTX
ENGLISH LEARNING ACTIVITY SHE W5Q1.pptxY
CHERIEANNAPRILSULIT1
 
PPTX
Constitutional Design Civics Class 9.pptx
bikesh692
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
PDF
A guide to responding to Section C essay tasks for the VCE English Language E...
jpinnuck
 
PPTX
Company - Meaning - Definition- Types of Company - Incorporation of Company
DevaRam6
 
PPTX
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PPTX
10CLA Term 3 Week 4 Study Techniques.pptx
mansk2
 
PPTX
Folding Off Hours in Gantt View in Odoo 18.2
Celine George
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
PPTX
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
Room booking management - Meeting Room In Odoo 17
Celine George
 
PDF
Living Systems Unveiled: Simplified Life Processes for Exam Success
omaiyairshad
 
PDF
Comprehensive Guide to Writing Effective Literature Reviews for Academic Publ...
AJAYI SAMUEL
 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
national medicinal plants board mpharm.pptx
SHAHEEN SHABBIR
 
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
ENGLISH LEARNING ACTIVITY SHE W5Q1.pptxY
CHERIEANNAPRILSULIT1
 
Constitutional Design Civics Class 9.pptx
bikesh692
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
A guide to responding to Section C essay tasks for the VCE English Language E...
jpinnuck
 
Company - Meaning - Definition- Types of Company - Incorporation of Company
DevaRam6
 
Modern analytical techniques used to characterize organic compounds. Birbhum ...
AyanHossain
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
10CLA Term 3 Week 4 Study Techniques.pptx
mansk2
 
Folding Off Hours in Gantt View in Odoo 18.2
Celine George
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Room booking management - Meeting Room In Odoo 17
Celine George
 
Living Systems Unveiled: Simplified Life Processes for Exam Success
omaiyairshad
 
Comprehensive Guide to Writing Effective Literature Reviews for Academic Publ...
AJAYI SAMUEL
 

R part iii

  • 1. Data available in R > data() > data("AirPassengers") > head(AirPassengers) [1] 112 118 132 129 121 135 > tail(AirPassengers) [1] 622 606 508 461 390 432 > str(AirPassengers) Time-Series [1:144] from 1949 to 1961: 112 118 132 129 121 135 148 148 136 119 ... > class(AirPassengers) [1] "ts" > help(ts) • The command data() loads data-sets available in R • head() and tail() command displays first few or last few values • str() shows the structure of an R object • class() shows the class of an R object • What does “ts” stand for?
  • 2. Try runif() and plot() commands …. runif(10) [1] 0.14350413 0.54293576 0.62881627 0.30278850 0.28030129 0.03784996 0.49483957 [8] 0.23571517 0.40072956 0.20327478 > plot(runif(10)) The runif() command generates U(0,1)10 random numbers between 0 and 1. These numbers have been plotted by the plot() function.
  • 3. A dataset in R: iris > head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa > tail(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width 145 6.7 3.3 5.7 2.5 146 6.7 3.0 5.2 2.3 147 6.3 2.5 5.0 1.9 148 6.5 3.0 5.2 2.0 149 6.2 3.4 5.4 2.3 150 5.9 3.0 5.1 1.8 Species virginica virginica virginica virginica virginica virginica The iris dataset contains measurement of 150 flowers, 50 each from 3 species : iris setosa, versicolor and virginica.
  • 4. Data frame in R: iris > str(iris) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... > class(iris) [1] "data.frame" • As you see, iris is not a simple vector but a composite “data frame” object made up of several component vectors as you can see in the output of class(iris) • You can think of a data frame as a matrix-like object - each row for each observational unit (here, a flower) - each column for each measurement made on the unit • But the str() function gives you more concise description on iris.
  • 5. Use of $ operator: iris > iris$Sepal.Length [1] 5.1 4.9 4.7 4.6 5.7 5.1 [21] 5.4 5.1 4.6 5.1 4.4 5.1 [41] 5.0 4.5 4.4 5.0 6.6 5.2 [61] 5.0 5.9 6.0 6.1 6.0 5.7 [81] 5.5 5.5 5.8 6.0 5.1 5.7 [101] 6.3 5.8 7.1 6.3 7.7 6.0 [121] 6.9 5.6 7.7 6.3 6.0 6.9 [141] 6.7 6.9 5.8 6.8 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5 4.9 5.0 5.5 4.9 5.1 4.8 5.1 4.6 5.3 5.0 7.0 6.4 6.9 5.5 6.5 5.7 6.3 4.9 5.6 6.7 5.6 5.8 6.2 5.6 5.9 6.1 6.3 6.1 6.4 6.6 6.8 6.7 5.4 6.0 6.7 6.3 5.6 5.5 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2 6.5 7.6 4.9 7.3 6.7 7.2 6.5 6.4 6.8 5.7 5.8 6.4 6.5 7.7 6.7 7.2 6.2 6.1 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7 6.3 6.4 6.7 6.7 6.3 6.5 6.2 5.9 Note that $-operator extracts individual components of a data frame. Try summary() and IQR() commands on iris$Sepal.Length and study the data
  • 6. summary() command: iris > summary(iris$Sepal.Length) Min. 1st Qu. Median Mean 3rd Qu. Max. 4.300 5.100 5.800 5.843 6.400 7.900 > summary(iris$Species) setosa versicolor virginica 50 50 50 > summary(iris) Sepal.Length Sepal.Width Petal.Length Min. :4.300 Min. :2.000 Min. :1.000 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 Median :5.800 Median :3.000 Median :4.350 Mean :5.843 Mean :3.057 Mean :3.758 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 Max. :7.900 Max. :4.400 Max. :6.900 Petal.Width Min. :0.100 1st Qu.:0.300 Median :1.300 Mean :1.199 3rd Qu.:1.800 Max. :2.500 Species setosa :50 versicolor:50 virginica :50 • Note the different output formats of using summary() • Species is summarized (by frequency distribution) as it is a categorical variable • The entire data frame iris is summarized by combining the summaries of its components
  • 7. class() command: iris > class(iris$Sepal.Length) [1] "numeric" > class(iris$Species) [1] "factor" > class(iris) [1] "data.frame" • Note that each R object has a class (“numeric”, “factor” etc.) • summary() is referred to as a generic function • When summary() is applied, R figures out the appropriate method and calls it
  • 8. More on summary() command > methods(summary) [1] summary.aov [4] summary.connection [7] summary.default [10] summary.glm [13] summary.loess* [16] summary.mlm [19] summary.PDF_Dictionary* [22] summary.POSIXlt [25] summary.princomp* [28] summary.stepfun [31] summary.tukeysmooth* summary.aovlist summary.data.frame summary.ecdf* summary.infl summary.manova summary.nls* summary.PDF_Stream* summary.ppr* summary.srcfile summary.stl* summary.aspell* summary.Date summary.factor summary.lm summary.matrix summary.packageStatus* summary.POSIXct summary.prcomp* summary.srcref summary.table Non-visible functions are asterisked • Objects of class “factor” are handled by summary.factor() • “data.frame”s are handled by summary.data.frame() • Numeric vectors are handled by summary.default()
  • 9. Try the following …. • • • • • • • • • attach() and detach() with iris xx <- 1:12 and then dim(xx) <- c(3,4) apply nrow(xx) and ncol(xx) dim(xx) <- c(2,2,3) yy <- matrix(1:12, nrows=3, byrow=TRUE rownames(yy) <- LETTERS[1:3] use colnames() zz <- cbind(A=1:4, B=5:8, C=9:12) rbind(zz,0)