SlideShare a Scribd company logo
www.r-squared.in/git-hub
R2 Academy R Programming
Variables & Data Types
R2 AcademyCourse Material
Slide 2
All the material related to this course are available at our website
Slides can be viewed at SlideShare
Scripts can be downloaded from GitHub
Videos can be viewed on our Youtube Channel
R2 AcademyObjectives
Slide 3
Variables
➢ What is a variable?
➢ How to create a variable?
➢ How to assign value?
➢ Understand rules for naming variables
Data Types
➢ Numeric
➢ Integer
➢ Character
➢ Logical
➢ Date/Time
R2 Academy
Slide 4
Variables
Case Study
Suppose you are computing the area of a circle whose radius is 3. In R, you can do this straight
away as shown below:
But you cannot reuse the radius or the area computed in any other computation. Let us see how
variables can change the above scenario and help us in reusing values and computations.
R2 AcademyWhat is a Variable?
Slide 5
➢ Variables are the fundamental elements of any programming language.
➢ They are used to represent values that are likely to change.
➢ They reference memory locations that store information/data.
Let us look at a simple case study to understand variables.
> 3.14 * 3 * 3
[1] 28.26
R2 AcademyCreating Variables
Slide 6
ASSIGNMENT OPERATOR
VARIABLE NAME VARIABLE VALUE
radius <- 3
We can store the value of the radius by creating a variable and assigning it the value. In this
case, we create a variable called radius and assign it the value 3. In the next slide, we will
see how to use this variable in computing the area of a circle.
R2 AcademyUsing Variables
Slide 7
We use variable to store value of radius and pi and use them to compute the area of the
circle. The area computed is itself stored in another variable called area.
R2 AcademyComponents Of A Variable
Slide 8
Components
Name
Memory
Address
Value Data Type
radius 0x6d8d8c8 3 Numeric
R2 Academy
Slide 9
Naming Conventions
Name must begin with
a letter. Do not use
numbers, dollar sign
($) or underscore ( _ ).
The name can contain
numbers or underscore.
Do not use dash (-) or
period (.).
Do not use names of
keywords and avoid
using the names of
built-in functions.
Variables are case
sensitive, so average
and Average would be
different variables.
Use names that are
descriptive. Generally,
variable names should
be nouns.
If name is made of
more than one word,
use underscore ( _ ) to
separate them.
R2 Academy
Slide 10
✓ Variables are the building blocks of a programming language
✓ Variables reference memory locations that store information/data
✓ An assignment operator assigns value to a variable.
✓ A variable has the following components:
○ Name
○ Memory Address
○ Value
○ Data Type
✓ Certain rules must be followed while naming variables
Recap..
R2 Academy
Slide 11
Data Types
R2 AcademyData Types
Slide 12
Data
Numeric Integer Character Logical Date/Time
1.25 1 "hello" TRUE
"2015-10-05
11:41:06 IST"
R2 AcademyNumeric
Slide 13
In R, numbers are represented by the type numeric. We will first create a variable and assign it a value.
After that, we will learn a few methods of checking the type of the variable:
R2 AcademyNumeric
Slide 14
If you have carefully observed, integers are also treated as type numeric. We will learn to create
variables of type integer in a short while. We also learnt a couple of new built in functions:
➢ class
Since R is an object oriented programming language, everything we create, whether it is a variable or a
function, is an object that belongs to a certain class. Hence, the class function returns the class/type
of the variable.
➢ is.numeric
is.numeric tests whether the variable is of type numeric. Note that while the class function returns
the data type, is.numeric returns TRUE or FALSE.
R2 AcademyInteger
Slide 15
Unless specified otherwise, integers are treated as type numeric. In this section, we will learn to create
variables of the type integer and to convert other data types to integer.
➢ First we create a variable number1 and assigned it the value 3 but
when we use the class function, we can see that R treats number1 as
type numeric and not integer.
➢ We then use as.integer to create a second variable number2.
Since we have specified that the variable is of type integer, R treats
number2 as integer.
➢ After that, we use is.integer to test if number1 and number2 are
integers.
R2 AcademyInteger
Slide 16
R2 AcademyInteger
Slide 17
➢ In the last part, we coerce other data types to type integer using as.integer.
R2 AcademyCharacter
Slide 18
Letters, words and group of words are represented by the type character. All data of type character
must be enclosed in single or double quotation marks. In fact, any value enclosed in quotes, will be
treated as character type.
➢ First we create two variables first_name and last_name. In the
first case, the value assigned was enclosed in double quotes, while in
the second case the value assigned was enclosed in single qoutes.
➢ In the next case, we do not use any quotes and R returns an error.
Hence, always ensure that you use single or double quotes while
creating variables of type character.
➢ After that, we use is.character to test if last_name is of type
character.
R2 AcademyCharacter
Slide 19
R2 AcademyCharacter
Slide 20
➢ In the last part, we coerce other data types to type character using as.character.
R2 AcademyLogical
Slide 21
Logical data types take only two values. Either TRUE or FALSE. Such data types are created when we
compare two objects in R using comparison and logical operators.
➢ First we create two variables x and y. They are assigned the values
TRUE and FALSE. After that, we use is.logical to check if they
are of type logical.
➢ In the next case, we use comparison operators and see that their
result is always a logical value.
➢ Finally, we coerce other data types to type logical using
as.logical and see the outcome.
R2 AcademyLogical
Slide 22
R2 AcademyLogical
Slide 23
TRUE is represented by all
numbers except 0. FALSE is
represented only by 0 and
no other numbers
R2 AcademyLogical
Slide 24
We coerce other data types to type logical using as.logical.
R2 AcademyDate/Time
Slide 25
Dates and time are represented by the data type date. We will briefly discuss ways to represent data
that contain dates and time. Use as.Date to coerce data to type date.
R2 AcademyDate/Time
Slide 26
In fact, there are a couple of other ways to represent date and time.
R2 Academy
Slide 27
● Numeric, Integer, Character,Logical and Date are the basic data types in R.
● class/typeof functions returns the data type of an object.
● is.data_type tests whether an object is of the specified data type
○ is.numeric
○ is.integer
○ is.character and
○ is.logical
● as.data_type will coerce objects to the specified data type
○ as.numeric
○ as.integer
○ as.character and
○ as.logical
Summary
R2 AcademyNext Steps...
Slide 28
In the next module:
✓ Understand the concept of vectors
✓ Create vectors of different data types
✓ Coercion of different data types
✓ Perform simple operations on vectors
✓ Handling missing data
✓ Learn to index/subset vectors
R2 Academy
Slide 29
Visit Rsquared Academy
for tutorials on:
→ R Programming
→ Business Analytics
→ Data Visualization
→ Web Applications
→ Package Development
→ Git & GitHub

More Related Content

What's hot (20)

PPTX
Exploratory data analysis with Python
Davis David
 
PPTX
3. R- list and data frame
krishna singh
 
PPTX
Decision Trees
Student
 
PPTX
Loops in R
Chris Orwa
 
PPTX
ML - Multiple Linear Regression
Andrew Ferlitsch
 
PPTX
Data Management in R
Sankhya_Analytics
 
PPT
R programming slides
Pankaj Saini
 
PPTX
Data analysis with R
ShareThis
 
PPTX
DMQL(Data Mining Query Language).pptx
Dr. Jasmine Beulah Gnanadurai
 
PDF
Simple linear regression
Avjinder (Avi) Kaler
 
PDF
Class ppt intro to r
JigsawAcademy2014
 
PPTX
Machine Learning-Linear regression
kishanthkumaar
 
PDF
R data-import, data-export
FAO
 
PPTX
R programming
Shantanu Patil
 
PPTX
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
PPT
ER-Model-ER Diagram
Saranya Natarajan
 
PPTX
Linear Regression
Abdullah al Mamun
 
PPTX
R Basics
Dr.E.N.Sathishkumar
 
PPTX
Exploratory Data Analysis
Umair Shafique
 
Exploratory data analysis with Python
Davis David
 
3. R- list and data frame
krishna singh
 
Decision Trees
Student
 
Loops in R
Chris Orwa
 
ML - Multiple Linear Regression
Andrew Ferlitsch
 
Data Management in R
Sankhya_Analytics
 
R programming slides
Pankaj Saini
 
Data analysis with R
ShareThis
 
DMQL(Data Mining Query Language).pptx
Dr. Jasmine Beulah Gnanadurai
 
Simple linear regression
Avjinder (Avi) Kaler
 
Class ppt intro to r
JigsawAcademy2014
 
Machine Learning-Linear regression
kishanthkumaar
 
R data-import, data-export
FAO
 
R programming
Shantanu Patil
 
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
ER-Model-ER Diagram
Saranya Natarajan
 
Linear Regression
Abdullah al Mamun
 
Exploratory Data Analysis
Umair Shafique
 

Viewers also liked (10)

PDF
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
Rsquared Academy
 
PDF
Data Visualization With R: Introduction
Rsquared Academy
 
PDF
R Programming: Introduction To R Packages
Rsquared Academy
 
PDF
R Programming: Getting Help In R
Rsquared Academy
 
PDF
R Programming: Introduction to Vectors
Rsquared Academy
 
PDF
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
PDF
R Programming: Numeric Functions In R
Rsquared Academy
 
PDF
R Programming: First Steps
Rsquared Academy
 
PDF
R Markdown Tutorial For Beginners
Rsquared Academy
 
PDF
RMySQL Tutorial For Beginners
Rsquared Academy
 
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
Rsquared Academy
 
Data Visualization With R: Introduction
Rsquared Academy
 
R Programming: Introduction To R Packages
Rsquared Academy
 
R Programming: Getting Help In R
Rsquared Academy
 
R Programming: Introduction to Vectors
Rsquared Academy
 
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
R Programming: Numeric Functions In R
Rsquared Academy
 
R Programming: First Steps
Rsquared Academy
 
R Markdown Tutorial For Beginners
Rsquared Academy
 
RMySQL Tutorial For Beginners
Rsquared Academy
 
Ad

Similar to R Programming: Variables & Data Types (20)

PDF
Variables & Data Types in R
Rsquared Academy
 
PDF
Unit 1 r studio programming required.pdf
arradhnasharma
 
DOCX
R Programming
AKSHANSH MISHRA
 
PPTX
R Data Types: A Beginner’s Guide to Data in R
subhashenia
 
PDF
R Programing language Notes Unit 5 Data Viz in R
en20cs301479
 
PDF
2 data types and operators in r
Dr Nisha Arora
 
PDF
R Programming - part 1.pdf
RohanBorgalli
 
PDF
FULL R PROGRAMMING METERIAL_2.pdf
attalurilalitha
 
PDF
7. basics
ExternalEvents
 
PPTX
Unit-5 BDS.pptx on basics of data science
SyedFahad39584
 
PPTX
Unit 1 financial analyticsfsddsdadsdsdsd
bchandrasep
 
PDF
R basics
FAO
 
PPTX
Introduction to R programming Language.pptx
kemetex
 
PPTX
Introduction To Programming In R for data analyst
ssuser26ff68
 
PPTX
program to create bell curve of a random normal distribution
sonali sonavane
 
PDF
R Programming For Beginners | R Language Tutorial | R Tutorial For Beginners ...
Edureka!
 
PPTX
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
PDF
5. R basics
FAO
 
PDF
R for Pythonistas (PyData NYC 2017)
Christopher Roach
 
Variables & Data Types in R
Rsquared Academy
 
Unit 1 r studio programming required.pdf
arradhnasharma
 
R Programming
AKSHANSH MISHRA
 
R Data Types: A Beginner’s Guide to Data in R
subhashenia
 
R Programing language Notes Unit 5 Data Viz in R
en20cs301479
 
2 data types and operators in r
Dr Nisha Arora
 
R Programming - part 1.pdf
RohanBorgalli
 
FULL R PROGRAMMING METERIAL_2.pdf
attalurilalitha
 
7. basics
ExternalEvents
 
Unit-5 BDS.pptx on basics of data science
SyedFahad39584
 
Unit 1 financial analyticsfsddsdadsdsdsd
bchandrasep
 
R basics
FAO
 
Introduction to R programming Language.pptx
kemetex
 
Introduction To Programming In R for data analyst
ssuser26ff68
 
program to create bell curve of a random normal distribution
sonali sonavane
 
R Programming For Beginners | R Language Tutorial | R Tutorial For Beginners ...
Edureka!
 
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
5. R basics
FAO
 
R for Pythonistas (PyData NYC 2017)
Christopher Roach
 
Ad

More from Rsquared Academy (20)

PDF
Handling Date & Time in R
Rsquared Academy
 
PDF
Market Basket Analysis in R
Rsquared Academy
 
PDF
Practical Introduction to Web scraping using R
Rsquared Academy
 
PDF
Joining Data with dplyr
Rsquared Academy
 
PDF
Explore Data using dplyr
Rsquared Academy
 
PDF
Data Wrangling with dplyr
Rsquared Academy
 
PDF
Writing Readable Code with Pipes
Rsquared Academy
 
PDF
Introduction to tibbles
Rsquared Academy
 
PDF
Read data from Excel spreadsheets into R
Rsquared Academy
 
PDF
Read/Import data from flat/delimited files into R
Rsquared Academy
 
PDF
How to install & update R packages?
Rsquared Academy
 
PDF
How to get help in R?
Rsquared Academy
 
PDF
Introduction to R
Rsquared Academy
 
PDF
Data Visualization With R: Learn To Combine Multiple Graphs
Rsquared Academy
 
PDF
R Data Visualization: Learn To Add Text Annotations To Plots
Rsquared Academy
 
PDF
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
Rsquared Academy
 
PDF
Data Visualization With R: Learn To Modify Color Of Plots
Rsquared Academy
 
PDF
Data Visualization With R
Rsquared Academy
 
PDF
R Programming: Mathematical Functions In R
Rsquared Academy
 
PDF
R Programming: Learn To Manipulate Strings In R
Rsquared Academy
 
Handling Date & Time in R
Rsquared Academy
 
Market Basket Analysis in R
Rsquared Academy
 
Practical Introduction to Web scraping using R
Rsquared Academy
 
Joining Data with dplyr
Rsquared Academy
 
Explore Data using dplyr
Rsquared Academy
 
Data Wrangling with dplyr
Rsquared Academy
 
Writing Readable Code with Pipes
Rsquared Academy
 
Introduction to tibbles
Rsquared Academy
 
Read data from Excel spreadsheets into R
Rsquared Academy
 
Read/Import data from flat/delimited files into R
Rsquared Academy
 
How to install & update R packages?
Rsquared Academy
 
How to get help in R?
Rsquared Academy
 
Introduction to R
Rsquared Academy
 
Data Visualization With R: Learn To Combine Multiple Graphs
Rsquared Academy
 
R Data Visualization: Learn To Add Text Annotations To Plots
Rsquared Academy
 
Data Visualization With R: Learn To Modify Font Of Graphical Parameters
Rsquared Academy
 
Data Visualization With R: Learn To Modify Color Of Plots
Rsquared Academy
 
Data Visualization With R
Rsquared Academy
 
R Programming: Mathematical Functions In R
Rsquared Academy
 
R Programming: Learn To Manipulate Strings In R
Rsquared Academy
 

Recently uploaded (20)

PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 

R Programming: Variables & Data Types

  • 1. www.r-squared.in/git-hub R2 Academy R Programming Variables & Data Types
  • 2. R2 AcademyCourse Material Slide 2 All the material related to this course are available at our website Slides can be viewed at SlideShare Scripts can be downloaded from GitHub Videos can be viewed on our Youtube Channel
  • 3. R2 AcademyObjectives Slide 3 Variables ➢ What is a variable? ➢ How to create a variable? ➢ How to assign value? ➢ Understand rules for naming variables Data Types ➢ Numeric ➢ Integer ➢ Character ➢ Logical ➢ Date/Time
  • 5. Case Study Suppose you are computing the area of a circle whose radius is 3. In R, you can do this straight away as shown below: But you cannot reuse the radius or the area computed in any other computation. Let us see how variables can change the above scenario and help us in reusing values and computations. R2 AcademyWhat is a Variable? Slide 5 ➢ Variables are the fundamental elements of any programming language. ➢ They are used to represent values that are likely to change. ➢ They reference memory locations that store information/data. Let us look at a simple case study to understand variables. > 3.14 * 3 * 3 [1] 28.26
  • 6. R2 AcademyCreating Variables Slide 6 ASSIGNMENT OPERATOR VARIABLE NAME VARIABLE VALUE radius <- 3 We can store the value of the radius by creating a variable and assigning it the value. In this case, we create a variable called radius and assign it the value 3. In the next slide, we will see how to use this variable in computing the area of a circle.
  • 7. R2 AcademyUsing Variables Slide 7 We use variable to store value of radius and pi and use them to compute the area of the circle. The area computed is itself stored in another variable called area.
  • 8. R2 AcademyComponents Of A Variable Slide 8 Components Name Memory Address Value Data Type radius 0x6d8d8c8 3 Numeric
  • 9. R2 Academy Slide 9 Naming Conventions Name must begin with a letter. Do not use numbers, dollar sign ($) or underscore ( _ ). The name can contain numbers or underscore. Do not use dash (-) or period (.). Do not use names of keywords and avoid using the names of built-in functions. Variables are case sensitive, so average and Average would be different variables. Use names that are descriptive. Generally, variable names should be nouns. If name is made of more than one word, use underscore ( _ ) to separate them.
  • 10. R2 Academy Slide 10 ✓ Variables are the building blocks of a programming language ✓ Variables reference memory locations that store information/data ✓ An assignment operator assigns value to a variable. ✓ A variable has the following components: ○ Name ○ Memory Address ○ Value ○ Data Type ✓ Certain rules must be followed while naming variables Recap..
  • 12. R2 AcademyData Types Slide 12 Data Numeric Integer Character Logical Date/Time 1.25 1 "hello" TRUE "2015-10-05 11:41:06 IST"
  • 13. R2 AcademyNumeric Slide 13 In R, numbers are represented by the type numeric. We will first create a variable and assign it a value. After that, we will learn a few methods of checking the type of the variable:
  • 14. R2 AcademyNumeric Slide 14 If you have carefully observed, integers are also treated as type numeric. We will learn to create variables of type integer in a short while. We also learnt a couple of new built in functions: ➢ class Since R is an object oriented programming language, everything we create, whether it is a variable or a function, is an object that belongs to a certain class. Hence, the class function returns the class/type of the variable. ➢ is.numeric is.numeric tests whether the variable is of type numeric. Note that while the class function returns the data type, is.numeric returns TRUE or FALSE.
  • 15. R2 AcademyInteger Slide 15 Unless specified otherwise, integers are treated as type numeric. In this section, we will learn to create variables of the type integer and to convert other data types to integer. ➢ First we create a variable number1 and assigned it the value 3 but when we use the class function, we can see that R treats number1 as type numeric and not integer. ➢ We then use as.integer to create a second variable number2. Since we have specified that the variable is of type integer, R treats number2 as integer. ➢ After that, we use is.integer to test if number1 and number2 are integers.
  • 17. R2 AcademyInteger Slide 17 ➢ In the last part, we coerce other data types to type integer using as.integer.
  • 18. R2 AcademyCharacter Slide 18 Letters, words and group of words are represented by the type character. All data of type character must be enclosed in single or double quotation marks. In fact, any value enclosed in quotes, will be treated as character type. ➢ First we create two variables first_name and last_name. In the first case, the value assigned was enclosed in double quotes, while in the second case the value assigned was enclosed in single qoutes. ➢ In the next case, we do not use any quotes and R returns an error. Hence, always ensure that you use single or double quotes while creating variables of type character. ➢ After that, we use is.character to test if last_name is of type character.
  • 20. R2 AcademyCharacter Slide 20 ➢ In the last part, we coerce other data types to type character using as.character.
  • 21. R2 AcademyLogical Slide 21 Logical data types take only two values. Either TRUE or FALSE. Such data types are created when we compare two objects in R using comparison and logical operators. ➢ First we create two variables x and y. They are assigned the values TRUE and FALSE. After that, we use is.logical to check if they are of type logical. ➢ In the next case, we use comparison operators and see that their result is always a logical value. ➢ Finally, we coerce other data types to type logical using as.logical and see the outcome.
  • 23. R2 AcademyLogical Slide 23 TRUE is represented by all numbers except 0. FALSE is represented only by 0 and no other numbers
  • 24. R2 AcademyLogical Slide 24 We coerce other data types to type logical using as.logical.
  • 25. R2 AcademyDate/Time Slide 25 Dates and time are represented by the data type date. We will briefly discuss ways to represent data that contain dates and time. Use as.Date to coerce data to type date.
  • 26. R2 AcademyDate/Time Slide 26 In fact, there are a couple of other ways to represent date and time.
  • 27. R2 Academy Slide 27 ● Numeric, Integer, Character,Logical and Date are the basic data types in R. ● class/typeof functions returns the data type of an object. ● is.data_type tests whether an object is of the specified data type ○ is.numeric ○ is.integer ○ is.character and ○ is.logical ● as.data_type will coerce objects to the specified data type ○ as.numeric ○ as.integer ○ as.character and ○ as.logical Summary
  • 28. R2 AcademyNext Steps... Slide 28 In the next module: ✓ Understand the concept of vectors ✓ Create vectors of different data types ✓ Coercion of different data types ✓ Perform simple operations on vectors ✓ Handling missing data ✓ Learn to index/subset vectors
  • 29. R2 Academy Slide 29 Visit Rsquared Academy for tutorials on: → R Programming → Business Analytics → Data Visualization → Web Applications → Package Development → Git & GitHub