SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Data types and Structures
in R
Rupak Roy
 Data type defines what sort of value it is. The very most commonly
used data types are numbers which is called as numeric values in R
and text which is again a character value.
 Data Structures can be defined as the structure of storing the data.
 Some of the common data structures
Vectors: a collection of values that has all the same data type.
The elements of a vector can be numeric vector or a
character vector. A vector can also be used to represent
a single variable in a data set .
Data Types
Rupak Roy
Factors: are also a collection of variables that are used to
categorize the data and store it as levels. It is similar to a
vector except they can store both strings and integers.
For example : number of gear types in the column.
Factor w/ 3 levels "3","4","5": 2 2 2 1 1 1 1 2 2 2 . means it has
a list of three types of gears i.e. 3, 4 and 5
Data Structures: factors
Rupak Roy
 Matrices: a two dimensional collection of values where all have
the same data type. The values are arranged
in rows and columns, used when the
data is a high dimensional array.
#creating a matrix and saving it as a R object
> A=matrix( c( 1,2,3,3,2,1), nrow= 3, ncol = 2)
Now we can access the elements using:
> A[1, ] #i.e. [row,column] Output=> 13
> A[ ,2] #i.e. [ , 2nd column] Output=> 321
> A[3,2] #i.e.[3rd row,2nd column] Output => 1
Data Structures: matrices
Rupak Roy
Data Structures: data frame
 Data frame: it is like a single table with rows and columns of same or different
data types.
 Let’s see how to create a data frame.
#vectors
> Student=c(1,2,3,4,5,6)
> pre_module_score=c(18,21,23,22,24,17)
> post_module_score=c(22,21,24,15,18,19)
> module_name=c( "graded", "graded", "non-graded",
"graded", "non-graded", "non-graded")
> test_scores= data.frame(Student,pre_module_score,post_module_score,
module_name)
Alternatively;
> test_scores=data.frame(Student=c(1,2,3,4,5,6), pre_module_score=c(18,21,23,22,24,17),
pos_module_score=c(22,21,24,15,18,19), module_name=c("graded","graded","non-
graded", "graded","non-graded","non- graded"))
 List: is a collection of objects of same or different data types.
#list
We can access
a list by its list
Position
Like list [[1]]
[1] bob
Data Structures: list
Rupak Roy
#dataframe: a table with rows and columns
#take the following vectors
> subject=c("geography","history","chemistry")
> testscores=c(77,61,65)
> remarks = c("very good","average","good") > Markscard =
> data.frame(subject,testscores,remarks)
> Markscard
OR
> Markscard<-data.frame(subject = c("geography","history","chemistry"),
testscores=c(77,61,65),remarks = c("very good","average","good"))
Examples in R
Rupak Roy
 To know what is the type of data structure the Markscard is use:
> class(Markscard)
And to access a element from the table or data.frame
> Markscard [,3] #i.e. Markscard [ row , column]
> Markscard[3,]
Let’s load the in-build R studio datasets.
>library(datasets)
#from the list of datasets we will call Iris dataset
>data(iris)
Examples in R
Rupak Roy
#to view the column names
> names(iris) or colnames(iris)
#to view the data structure of the iris data set
> str(iris)
#to know the dimensions of the iris data set
> dim(iris)
150 rows and 5 columns
#to view the number of rows and columns
> nrow(iris) and > ncol(iris)
Examples in R
Rupak Roy
Examples in R
#to view the whole dataset.
>view(iris)
#to view the top or the bottom most values from the dataset.
> head(iris)
> Tail(iris)
#to view only few top or the bottom most values from the dataset.
> head(iris,10) > tail(iris,10)
#to know more about head, tail function or any functions use:
> ?head
#to view a range of rows or columns from the dataset use
> iris[15:20,] #i.e. from rows 15 to 20
> iris[15:20,2:3] #i.e. from rows 15 to 20 and column 2 and 3
Rupak Roy
#we can access all the values of a particular column using $
> iris$Species
#Or we can access a particular value from the column using:
>iris$Species[3] i.e. the 3rd row of species column
#Else a range of values/rows from a particular column using:
> iris$Species[50:10] i.e. from row 50 to 100
#to have a quick summary of the dataset use:
> summary(iris)
#we can also check the data type of a variable using:
> is.character(iris$Species)
> is.numeric(iris$PetalLength)
Examples in R
Rupak Roy
Examples in R
#we can use the ‘attach’ function to take all the columns of iris
data set and create an individual objects so that we don’t have
to use $ to call the columns of the dataset.
> attach(iris)
> Species #‘Species’ previously accessed by using iris$Species
#it is better to detach the dataset after we are done with the
dataset as we are aware that R uses systems RAM to perform
its tasks.
> detach(iris)
Rupak Roy
#we can view the working directory of R by
> getwd()
#we also set the work directory by our choice by
> setwd(“c:/Users/data2dimensions/documents”)
#it is preferable to use:
> gc() i.e. garbage collection (GC) automatically releases memory
when an object is no longer used. It does this by tracking how many names
point to each object and when there are no names pointing to an object, it
deletes that object.
Examples in R
Rupak Roy
 Next :
We will learn how to import and export data in R
Data types and structures
Rupak Roy

Más contenido relacionado

La actualidad más candente

Data visualization using R
Data visualization using RData visualization using R
Data visualization using RUmmiya Mohammedi
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data TypesRsquared Academy
 
Classification in data mining
Classification in data mining Classification in data mining
Classification in data mining Sulman Ahmed
 
Import and Export Big Data using R Studio
Import and Export Big Data using R StudioImport and Export Big Data using R Studio
Import and Export Big Data using R StudioRupak Roy
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with RYanchang Zhao
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingVictor Ordu
 
R programming presentation
R programming presentationR programming presentation
R programming presentationAkshat Sharma
 
Introduction to Rstudio
Introduction to RstudioIntroduction to Rstudio
Introduction to RstudioOlga Scrivner
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Guy Lebanon
 
Introduction to data analysis using R
Introduction to data analysis using RIntroduction to data analysis using R
Introduction to data analysis using RVictoria López
 
R basics
R basicsR basics
R basicsFAO
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In RRsquared Academy
 
R Programming Language
R Programming LanguageR Programming Language
R Programming LanguageNareshKarela1
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R StudioRupak Roy
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to MatricesRsquared Academy
 

La actualidad más candente (20)

Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
 
Classification in data mining
Classification in data mining Classification in data mining
Classification in data mining
 
Import and Export Big Data using R Studio
Import and Export Big Data using R StudioImport and Export Big Data using R Studio
Import and Export Big Data using R Studio
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with R
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
R programming presentation
R programming presentationR programming presentation
R programming presentation
 
Introduction to Rstudio
Introduction to RstudioIntroduction to Rstudio
Introduction to Rstudio
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Introduction to data analysis using R
Introduction to data analysis using RIntroduction to data analysis using R
Introduction to data analysis using R
 
R basics
R basicsR basics
R basics
 
Class ppt intro to r
Class ppt intro to rClass ppt intro to r
Class ppt intro to r
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
Step By Step Guide to Learn R
Step By Step Guide to Learn RStep By Step Guide to Learn R
Step By Step Guide to Learn R
 
Programming in R
Programming in RProgramming in R
Programming in R
 
R Programming Language
R Programming LanguageR Programming Language
R Programming Language
 
02 Data Mining
02 Data Mining02 Data Mining
02 Data Mining
 
Introduction to R and R Studio
Introduction to R and R StudioIntroduction to R and R Studio
Introduction to R and R Studio
 
R studio
R studio R studio
R studio
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 

Similar a Data Types and Structures in R

Similar a Data Types and Structures in R (20)

Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Array
ArrayArray
Array
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
 
R교육1
R교육1R교육1
R교육1
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
 
Array
ArrayArray
Array
 
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptxfINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptx
 
Array
ArrayArray
Array
 
Data types in r
Data types in rData types in r
Data types in r
 
R Programming Tutorial for Beginners - -TIB Academy
R Programming Tutorial for Beginners - -TIB AcademyR Programming Tutorial for Beginners - -TIB Academy
R Programming Tutorial for Beginners - -TIB Academy
 
Arrays
ArraysArrays
Arrays
 
R data types
R   data typesR   data types
R data types
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
 
Ggplot2 work
Ggplot2 workGgplot2 work
Ggplot2 work
 
Array 2 hina
Array 2 hina Array 2 hina
Array 2 hina
 
Ch08
Ch08Ch08
Ch08
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
arrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdfarrays-130116232821-phpapp02.pdf
arrays-130116232821-phpapp02.pdf
 

Más de Rupak Roy

Hierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPHierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPRupak Roy
 
Clustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPClustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPRupak Roy
 
Network Analysis - NLP
Network Analysis  - NLPNetwork Analysis  - NLP
Network Analysis - NLPRupak Roy
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLPRupak Roy
 
Sentiment Analysis Practical Steps
Sentiment Analysis Practical StepsSentiment Analysis Practical Steps
Sentiment Analysis Practical StepsRupak Roy
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment AnalysisRupak Roy
 
Text Mining using Regular Expressions
Text Mining using Regular ExpressionsText Mining using Regular Expressions
Text Mining using Regular ExpressionsRupak Roy
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining Rupak Roy
 
Apache Hbase Architecture
Apache Hbase ArchitectureApache Hbase Architecture
Apache Hbase ArchitectureRupak Roy
 
Introduction to Hbase
Introduction to Hbase Introduction to Hbase
Introduction to Hbase Rupak Roy
 
Apache Hive Table Partition and HQL
Apache Hive Table Partition and HQLApache Hive Table Partition and HQL
Apache Hive Table Partition and HQLRupak Roy
 
Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Rupak Roy
 
Introductive to Hive
Introductive to Hive Introductive to Hive
Introductive to Hive Rupak Roy
 
Scoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMSScoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMSRupak Roy
 
Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode Rupak Roy
 
Introduction to scoop and its functions
Introduction to scoop and its functionsIntroduction to scoop and its functions
Introduction to scoop and its functionsRupak Roy
 
Introduction to Flume
Introduction to FlumeIntroduction to Flume
Introduction to FlumeRupak Roy
 
Apache Pig Relational Operators - II
Apache Pig Relational Operators - II Apache Pig Relational Operators - II
Apache Pig Relational Operators - II Rupak Roy
 
Passing Parameters using File and Command Line
Passing Parameters using File and Command LinePassing Parameters using File and Command Line
Passing Parameters using File and Command LineRupak Roy
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations Rupak Roy
 

Más de Rupak Roy (20)

Hierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPHierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLP
 
Clustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPClustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLP
 
Network Analysis - NLP
Network Analysis  - NLPNetwork Analysis  - NLP
Network Analysis - NLP
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLP
 
Sentiment Analysis Practical Steps
Sentiment Analysis Practical StepsSentiment Analysis Practical Steps
Sentiment Analysis Practical Steps
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment Analysis
 
Text Mining using Regular Expressions
Text Mining using Regular ExpressionsText Mining using Regular Expressions
Text Mining using Regular Expressions
 
Introduction to Text Mining
Introduction to Text Mining Introduction to Text Mining
Introduction to Text Mining
 
Apache Hbase Architecture
Apache Hbase ArchitectureApache Hbase Architecture
Apache Hbase Architecture
 
Introduction to Hbase
Introduction to Hbase Introduction to Hbase
Introduction to Hbase
 
Apache Hive Table Partition and HQL
Apache Hive Table Partition and HQLApache Hive Table Partition and HQL
Apache Hive Table Partition and HQL
 
Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export Installing Apache Hive, internal and external table, import-export
Installing Apache Hive, internal and external table, import-export
 
Introductive to Hive
Introductive to Hive Introductive to Hive
Introductive to Hive
 
Scoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMSScoop Job, import and export to RDBMS
Scoop Job, import and export to RDBMS
 
Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode Apache Scoop - Import with Append mode and Last Modified mode
Apache Scoop - Import with Append mode and Last Modified mode
 
Introduction to scoop and its functions
Introduction to scoop and its functionsIntroduction to scoop and its functions
Introduction to scoop and its functions
 
Introduction to Flume
Introduction to FlumeIntroduction to Flume
Introduction to Flume
 
Apache Pig Relational Operators - II
Apache Pig Relational Operators - II Apache Pig Relational Operators - II
Apache Pig Relational Operators - II
 
Passing Parameters using File and Command Line
Passing Parameters using File and Command LinePassing Parameters using File and Command Line
Passing Parameters using File and Command Line
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations
 

Último

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
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
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
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
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Último (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.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
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Data Types and Structures in R

  • 1. Data types and Structures in R Rupak Roy
  • 2.  Data type defines what sort of value it is. The very most commonly used data types are numbers which is called as numeric values in R and text which is again a character value.  Data Structures can be defined as the structure of storing the data.  Some of the common data structures Vectors: a collection of values that has all the same data type. The elements of a vector can be numeric vector or a character vector. A vector can also be used to represent a single variable in a data set . Data Types Rupak Roy
  • 3. Factors: are also a collection of variables that are used to categorize the data and store it as levels. It is similar to a vector except they can store both strings and integers. For example : number of gear types in the column. Factor w/ 3 levels "3","4","5": 2 2 2 1 1 1 1 2 2 2 . means it has a list of three types of gears i.e. 3, 4 and 5 Data Structures: factors Rupak Roy
  • 4.  Matrices: a two dimensional collection of values where all have the same data type. The values are arranged in rows and columns, used when the data is a high dimensional array. #creating a matrix and saving it as a R object > A=matrix( c( 1,2,3,3,2,1), nrow= 3, ncol = 2) Now we can access the elements using: > A[1, ] #i.e. [row,column] Output=> 13 > A[ ,2] #i.e. [ , 2nd column] Output=> 321 > A[3,2] #i.e.[3rd row,2nd column] Output => 1 Data Structures: matrices Rupak Roy
  • 5. Data Structures: data frame  Data frame: it is like a single table with rows and columns of same or different data types.  Let’s see how to create a data frame. #vectors > Student=c(1,2,3,4,5,6) > pre_module_score=c(18,21,23,22,24,17) > post_module_score=c(22,21,24,15,18,19) > module_name=c( "graded", "graded", "non-graded", "graded", "non-graded", "non-graded") > test_scores= data.frame(Student,pre_module_score,post_module_score, module_name) Alternatively; > test_scores=data.frame(Student=c(1,2,3,4,5,6), pre_module_score=c(18,21,23,22,24,17), pos_module_score=c(22,21,24,15,18,19), module_name=c("graded","graded","non- graded", "graded","non-graded","non- graded"))
  • 6.  List: is a collection of objects of same or different data types. #list We can access a list by its list Position Like list [[1]] [1] bob Data Structures: list Rupak Roy
  • 7. #dataframe: a table with rows and columns #take the following vectors > subject=c("geography","history","chemistry") > testscores=c(77,61,65) > remarks = c("very good","average","good") > Markscard = > data.frame(subject,testscores,remarks) > Markscard OR > Markscard<-data.frame(subject = c("geography","history","chemistry"), testscores=c(77,61,65),remarks = c("very good","average","good")) Examples in R Rupak Roy
  • 8.  To know what is the type of data structure the Markscard is use: > class(Markscard) And to access a element from the table or data.frame > Markscard [,3] #i.e. Markscard [ row , column] > Markscard[3,] Let’s load the in-build R studio datasets. >library(datasets) #from the list of datasets we will call Iris dataset >data(iris) Examples in R Rupak Roy
  • 9. #to view the column names > names(iris) or colnames(iris) #to view the data structure of the iris data set > str(iris) #to know the dimensions of the iris data set > dim(iris) 150 rows and 5 columns #to view the number of rows and columns > nrow(iris) and > ncol(iris) Examples in R Rupak Roy
  • 10. Examples in R #to view the whole dataset. >view(iris) #to view the top or the bottom most values from the dataset. > head(iris) > Tail(iris) #to view only few top or the bottom most values from the dataset. > head(iris,10) > tail(iris,10) #to know more about head, tail function or any functions use: > ?head #to view a range of rows or columns from the dataset use > iris[15:20,] #i.e. from rows 15 to 20 > iris[15:20,2:3] #i.e. from rows 15 to 20 and column 2 and 3 Rupak Roy
  • 11. #we can access all the values of a particular column using $ > iris$Species #Or we can access a particular value from the column using: >iris$Species[3] i.e. the 3rd row of species column #Else a range of values/rows from a particular column using: > iris$Species[50:10] i.e. from row 50 to 100 #to have a quick summary of the dataset use: > summary(iris) #we can also check the data type of a variable using: > is.character(iris$Species) > is.numeric(iris$PetalLength) Examples in R Rupak Roy
  • 12. Examples in R #we can use the ‘attach’ function to take all the columns of iris data set and create an individual objects so that we don’t have to use $ to call the columns of the dataset. > attach(iris) > Species #‘Species’ previously accessed by using iris$Species #it is better to detach the dataset after we are done with the dataset as we are aware that R uses systems RAM to perform its tasks. > detach(iris) Rupak Roy
  • 13. #we can view the working directory of R by > getwd() #we also set the work directory by our choice by > setwd(“c:/Users/data2dimensions/documents”) #it is preferable to use: > gc() i.e. garbage collection (GC) automatically releases memory when an object is no longer used. It does this by tracking how many names point to each object and when there are no names pointing to an object, it deletes that object. Examples in R Rupak Roy
  • 14.  Next : We will learn how to import and export data in R Data types and structures Rupak Roy