SlideShare una empresa de Scribd logo
1 de 9
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)

Más contenido relacionado

La actualidad más candente

My sql presentation
My sql presentationMy sql presentation
My sql presentationNikhil Jain
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPlotly
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015Phillip Trelford
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with RYanchang Zhao
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceTobias Pfeiffer
 
Implementing pseudo-keywords through Functional Programing
Implementing pseudo-keywords through Functional ProgramingImplementing pseudo-keywords through Functional Programing
Implementing pseudo-keywords through Functional ProgramingVincent Pradeilles
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL codeSimon Hoyle
 
Lecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickLecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickokelloerick
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Ohgyun Ahn
 

La actualidad más candente (16)

My sql presentation
My sql presentationMy sql presentation
My sql presentation
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with R
 
Array vs set in JavaScript
Array vs set in JavaScriptArray vs set in JavaScript
Array vs set in JavaScript
 
Quick reference for Grafana
Quick reference for GrafanaQuick reference for Grafana
Quick reference for Grafana
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
How fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practiceHow fast ist it really? Benchmarking in practice
How fast ist it really? Benchmarking in practice
 
Implementing pseudo-keywords through Functional Programing
Implementing pseudo-keywords through Functional ProgramingImplementing pseudo-keywords through Functional Programing
Implementing pseudo-keywords through Functional Programing
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
 
Lecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickLecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erick
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Python Usage (5-minute-summary)
Python Usage (5-minute-summary)Python Usage (5-minute-summary)
Python Usage (5-minute-summary)
 
PHP 101
PHP 101 PHP 101
PHP 101
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 

Destacado

(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
(OBN) Hout + Heterogeniteit + Hinterland - Marieke de LangeSovon Vogelonderzoek
 
The Loch Ness Monter
The Loch Ness MonterThe Loch Ness Monter
The Loch Ness Montere117024a
 
画像を使ったバナー作成【実践編】
画像を使ったバナー作成【実践編】画像を使ったバナー作成【実践編】
画像を使ったバナー作成【実践編】ec-campus
 
HTML(5) and CSS(3) for beginners - I
HTML(5) and CSS(3) for beginners - IHTML(5) and CSS(3) for beginners - I
HTML(5) and CSS(3) for beginners - Ivincentleeuwen
 
Statistics
StatisticsStatistics
Statisticspikuoec
 

Destacado (8)

(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
(OBN) Hout + Heterogeniteit + Hinterland - Marieke de Lange
 
If clause
If clauseIf clause
If clause
 
The Loch Ness Monter
The Loch Ness MonterThe Loch Ness Monter
The Loch Ness Monter
 
画像を使ったバナー作成【実践編】
画像を使ったバナー作成【実践編】画像を使ったバナー作成【実践編】
画像を使ったバナー作成【実践編】
 
HTML(5) and CSS(3) for beginners - I
HTML(5) and CSS(3) for beginners - IHTML(5) and CSS(3) for beginners - I
HTML(5) and CSS(3) for beginners - I
 
Cours animation et multimédia:
Cours animation et multimédia:Cours animation et multimédia:
Cours animation et multimédia:
 
Statr sessions 4 to 6
Statr sessions 4 to 6Statr sessions 4 to 6
Statr sessions 4 to 6
 
Statistics
StatisticsStatistics
Statistics
 

Similar a Data Analysis in R: Key Commands for Loading, Summarizing and Visualizing Data

01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdfzehiwot hone
 
RDataMining slides-data-exploration-visualisation
RDataMining slides-data-exploration-visualisationRDataMining slides-data-exploration-visualisation
RDataMining slides-data-exploration-visualisationYanchang Zhao
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.Dr. Volkan OBAN
 
Data structure array
Data structure  arrayData structure  array
Data structure arrayMajidHamidAli
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciencesalexstorer
 
Cloudera - A Taste of random decision forests
Cloudera - A Taste of random decision forestsCloudera - A Taste of random decision forests
Cloudera - A Taste of random decision forestsDataconomy Media
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Introduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptIntroduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptWill Kurt
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2Leandro Lima
 
Scala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 SunumuScala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 SunumuVolkan Yazıcı
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxcarliotwaycave
 

Similar a Data Analysis in R: Key Commands for Loading, Summarizing and Visualizing Data (20)

01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdf
 
RDataMining slides-data-exploration-visualisation
RDataMining slides-data-exploration-visualisationRDataMining slides-data-exploration-visualisation
RDataMining slides-data-exploration-visualisation
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
 
Arrays
ArraysArrays
Arrays
 
R programming language
R programming languageR programming language
R programming language
 
R programming
R programmingR programming
R programming
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
 
Cloudera - A Taste of random decision forests
Cloudera - A Taste of random decision forestsCloudera - A Taste of random decision forests
Cloudera - A Taste of random decision forests
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Rsplit apply combine
Rsplit apply combineRsplit apply combine
Rsplit apply combine
 
Introduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptIntroduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScript
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Workshop on command line tools - day 2
Workshop on command line tools - day 2Workshop on command line tools - day 2
Workshop on command line tools - day 2
 
R and data mining
R and data miningR and data mining
R and data mining
 
Scala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 SunumuScala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 Sunumu
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Array BPK 2
Array BPK 2Array BPK 2
Array BPK 2
 

Más de Ruru Chowdhury

The One With The Wizards and Dragons. Prelims
The One With The Wizards and Dragons. PrelimsThe One With The Wizards and Dragons. Prelims
The One With The Wizards and Dragons. PrelimsRuru Chowdhury
 
The One With The Wizards and Dragons. Finals
The One With The Wizards and Dragons. FinalsThe One With The Wizards and Dragons. Finals
The One With The Wizards and Dragons. FinalsRuru Chowdhury
 
Statr session 25 and 26
Statr session 25 and 26Statr session 25 and 26
Statr session 25 and 26Ruru Chowdhury
 
Statr session 23 and 24
Statr session 23 and 24Statr session 23 and 24
Statr session 23 and 24Ruru Chowdhury
 
Statr session 21 and 22
Statr session 21 and 22Statr session 21 and 22
Statr session 21 and 22Ruru Chowdhury
 
Statr session 19 and 20
Statr session 19 and 20Statr session 19 and 20
Statr session 19 and 20Ruru Chowdhury
 
Statr session 17 and 18
Statr session 17 and 18Statr session 17 and 18
Statr session 17 and 18Ruru Chowdhury
 
Statr session 17 and 18 (ASTR)
Statr session 17 and 18 (ASTR)Statr session 17 and 18 (ASTR)
Statr session 17 and 18 (ASTR)Ruru Chowdhury
 
Statr session 15 and 16
Statr session 15 and 16Statr session 15 and 16
Statr session 15 and 16Ruru Chowdhury
 
Statr session14, Jan 11
Statr session14, Jan 11Statr session14, Jan 11
Statr session14, Jan 11Ruru Chowdhury
 
JM Statr session 13, Jan 11
JM Statr session 13, Jan 11JM Statr session 13, Jan 11
JM Statr session 13, Jan 11Ruru Chowdhury
 
Statr sessions 11 to 12
Statr sessions 11 to 12Statr sessions 11 to 12
Statr sessions 11 to 12Ruru Chowdhury
 
Nosql part1 8th December
Nosql part1 8th December Nosql part1 8th December
Nosql part1 8th December Ruru Chowdhury
 
Statr sessions 9 to 10
Statr sessions 9 to 10Statr sessions 9 to 10
Statr sessions 9 to 10Ruru Chowdhury
 

Más de Ruru Chowdhury (20)

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

Último

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 

Último (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 

Data Analysis in R: Key Commands for Loading, Summarizing and Visualizing Data

  • 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)