SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
krishna singh
 
Unit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptxUnit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Import Data using R
Import Data using R Import Data using R
Import Data using R
Rupak Roy
 
R data-import, data-export
R data-import, data-exportR data-import, data-export
R data-import, data-export
FAO
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
krishna singh
 
6. R data structures
6. R data structures6. R data structures
6. R data structures
ExternalEvents
 
Vector in R
Vector in RVector in R
Vector in R
venkata surya sunil Modekurthy
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
Neeru Mittal
 
Exploratory data analysis with Python
Exploratory data analysis with PythonExploratory data analysis with Python
Exploratory data analysis with Python
Davis David
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
Dr Nisha Arora
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
Ummiya Mohammedi
 
5.1 mining data streams
5.1 mining data streams5.1 mining data streams
5.1 mining data streams
Krish_ver2
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
Data frame operations
Data frame operationsData frame operations
Data frame operations
19MSS011dhanyatha
 
R data types
R   data typesR   data types
R data types
Learnbay Datascience
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
Md. Sohag Miah
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalities
Krish_ver2
 
Kmp
KmpKmp
Kmp
akruthi k
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
krishna singh
 
Import Data using R
Import Data using R Import Data using R
Import Data using R
Rupak Roy
 
R data-import, data-export
R data-import, data-exportR data-import, data-export
R data-import, data-export
FAO
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
krishna singh
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
Neeru Mittal
 
Exploratory data analysis with Python
Exploratory data analysis with PythonExploratory data analysis with Python
Exploratory data analysis with Python
Davis David
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
Ummiya Mohammedi
 
5.1 mining data streams
5.1 mining data streams5.1 mining data streams
5.1 mining data streams
Krish_ver2
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalities
Krish_ver2
 

Similar to Data Types and Structures in R (20)

Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Array
ArrayArray
Array
Deep Shah
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
Rsquared Academy
 
R교육1
R교육1R교육1
R교육1
Kangwook Lee
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
lakshmanarao027MVGRC
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
UtkarshGAUTAM49
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
AmaanRizvi6
 
05slide_arrays_creation_searching_sorting.ppt
05slide_arrays_creation_searching_sorting.ppt05slide_arrays_creation_searching_sorting.ppt
05slide_arrays_creation_searching_sorting.ppt
ramesh504657
 
Introduction to R programming Language.pptx
Introduction to R programming Language.pptxIntroduction to R programming Language.pptx
Introduction to R programming Language.pptx
kemetex
 
Array
ArrayArray
Array
PralhadKhanal1
 
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
dataKarthik
 
23. SQL and Database.pptx this ppt file is important for class 12
23. SQL and Database.pptx this ppt file is important for class 1223. SQL and Database.pptx this ppt file is important for class 12
23. SQL and Database.pptx this ppt file is important for class 12
jayedhossain1519
 
Array
ArrayArray
Array
Tejas Patel
 
Data types in r
Data types in rData types in r
Data types in r
Pramod Rathore
 
11. Programming(BS-phy6)-Lecture11+12 .pdf
11. Programming(BS-phy6)-Lecture11+12 .pdf11. Programming(BS-phy6)-Lecture11+12 .pdf
11. Programming(BS-phy6)-Lecture11+12 .pdf
UmarIslam14
 
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
rajkamaltibacademy
 
Arrays
ArraysArrays
Arrays
Chirag vasava
 
Exploratory Data Analysis in Machine Learning
Exploratory Data Analysis in Machine LearningExploratory Data Analysis in Machine Learning
Exploratory Data Analysis in Machine Learning
Prasad Deshmukh
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
kalai75
 
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffsR1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
Rsquared Academy
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
UtkarshGAUTAM49
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
AmaanRizvi6
 
05slide_arrays_creation_searching_sorting.ppt
05slide_arrays_creation_searching_sorting.ppt05slide_arrays_creation_searching_sorting.ppt
05slide_arrays_creation_searching_sorting.ppt
ramesh504657
 
Introduction to R programming Language.pptx
Introduction to R programming Language.pptxIntroduction to R programming Language.pptx
Introduction to R programming Language.pptx
kemetex
 
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
dataKarthik
 
23. SQL and Database.pptx this ppt file is important for class 12
23. SQL and Database.pptx this ppt file is important for class 1223. SQL and Database.pptx this ppt file is important for class 12
23. SQL and Database.pptx this ppt file is important for class 12
jayedhossain1519
 
11. Programming(BS-phy6)-Lecture11+12 .pdf
11. Programming(BS-phy6)-Lecture11+12 .pdf11. Programming(BS-phy6)-Lecture11+12 .pdf
11. Programming(BS-phy6)-Lecture11+12 .pdf
UmarIslam14
 
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
rajkamaltibacademy
 
Exploratory Data Analysis in Machine Learning
Exploratory Data Analysis in Machine LearningExploratory Data Analysis in Machine Learning
Exploratory Data Analysis in Machine Learning
Prasad Deshmukh
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
kalai75
 
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffsR1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
Ad

More from Rupak Roy (20)

Hierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPHierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLP
Rupak Roy
 
Clustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPClustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLP
Rupak Roy
 
Network Analysis - NLP
Network Analysis  - NLPNetwork Analysis  - NLP
Network Analysis - NLP
Rupak Roy
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLP
Rupak Roy
 
Sentiment Analysis Practical Steps
Sentiment Analysis Practical StepsSentiment Analysis Practical Steps
Sentiment Analysis Practical Steps
Rupak Roy
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment Analysis
Rupak Roy
 
Text Mining using Regular Expressions
Text Mining using Regular ExpressionsText Mining using Regular Expressions
Text Mining using Regular Expressions
Rupak 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 Architecture
Rupak 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 HQL
Rupak 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 RDBMS
Rupak 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 functions
Rupak Roy
 
Introduction to Flume
Introduction to FlumeIntroduction to Flume
Introduction to Flume
Rupak 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 Line
Rupak Roy
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations
Rupak Roy
 
Hierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLPHierarchical Clustering - Text Mining/NLP
Hierarchical Clustering - Text Mining/NLP
Rupak Roy
 
Clustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLPClustering K means and Hierarchical - NLP
Clustering K means and Hierarchical - NLP
Rupak Roy
 
Network Analysis - NLP
Network Analysis  - NLPNetwork Analysis  - NLP
Network Analysis - NLP
Rupak Roy
 
Topic Modeling - NLP
Topic Modeling - NLPTopic Modeling - NLP
Topic Modeling - NLP
Rupak Roy
 
Sentiment Analysis Practical Steps
Sentiment Analysis Practical StepsSentiment Analysis Practical Steps
Sentiment Analysis Practical Steps
Rupak Roy
 
NLP - Sentiment Analysis
NLP - Sentiment AnalysisNLP - Sentiment Analysis
NLP - Sentiment Analysis
Rupak Roy
 
Text Mining using Regular Expressions
Text Mining using Regular ExpressionsText Mining using Regular Expressions
Text Mining using Regular Expressions
Rupak 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 Architecture
Rupak 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 HQL
Rupak 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 RDBMS
Rupak 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 functions
Rupak Roy
 
Introduction to Flume
Introduction to FlumeIntroduction to Flume
Introduction to Flume
Rupak 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 Line
Rupak Roy
 
Apache PIG Relational Operations
Apache PIG Relational Operations Apache PIG Relational Operations
Apache PIG Relational Operations
Rupak Roy
 
Ad

Recently uploaded (20)

World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 

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