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)

PDF
Python list
Mohammed Sikander
 
PPT
Dbms relational model
Chirag vasava
 
PDF
Introduction to R Programming
izahn
 
PPTX
ML - Multiple Linear Regression
Andrew Ferlitsch
 
PPTX
Type casting in c programming
Rumman Ansari
 
PDF
Operators in python
Prabhakaran V M
 
PPTX
sorting and its types
SIVASHANKARIRAJAN
 
PPTX
R programming
Shantanu Patil
 
PDF
Data structure ppt
Prof. Dr. K. Adisesha
 
PPTX
Step By Step Guide to Learn R
Venkata Reddy Konasani
 
PDF
Python algorithm
Prof. Dr. K. Adisesha
 
PPT
Python Pandas
Sunil OS
 
PPTX
Relational database
Megha Sharma
 
PPTX
Introduction to pandas
Piyush rai
 
PDF
Dbms 10: Conversion of ER model to Relational Model
Amiya9439793168
 
PPTX
Python dictionary
Mohammed Sikander
 
PPTX
Chapter 15 Lists
Praveen M Jigajinni
 
PPT
11 Database Concepts
Praveen M Jigajinni
 
PDF
Python set
Mohammed Sikander
 
Python list
Mohammed Sikander
 
Dbms relational model
Chirag vasava
 
Introduction to R Programming
izahn
 
ML - Multiple Linear Regression
Andrew Ferlitsch
 
Type casting in c programming
Rumman Ansari
 
Operators in python
Prabhakaran V M
 
sorting and its types
SIVASHANKARIRAJAN
 
R programming
Shantanu Patil
 
Data structure ppt
Prof. Dr. K. Adisesha
 
Step By Step Guide to Learn R
Venkata Reddy Konasani
 
Python algorithm
Prof. Dr. K. Adisesha
 
Python Pandas
Sunil OS
 
Relational database
Megha Sharma
 
Introduction to pandas
Piyush rai
 
Dbms 10: Conversion of ER model to Relational Model
Amiya9439793168
 
Python dictionary
Mohammed Sikander
 
Chapter 15 Lists
Praveen M Jigajinni
 
11 Database Concepts
Praveen M Jigajinni
 
Python set
Mohammed Sikander
 

Viewers also liked (11)

PDF
R Programming: Introduction to Matrices
Rsquared Academy
 
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
 
R Programming: Introduction to Matrices
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 Basics
Dr.E.N.Sathishkumar
 
PPTX
R Data Types: A Beginner’s Guide to Data in R
subhashenia
 
PPTX
r language ...basic introduction Unit 1 R.pptx
pallavprem2003
 
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
 
PPTX
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
PDF
R Programming For Beginners | R Language Tutorial | R Tutorial For Beginners ...
Edureka!
 
PPTX
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
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 language ...basic introduction Unit 1 R.pptx
pallavprem2003
 
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
 
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
R Programming For Beginners | R Language Tutorial | R Tutorial For Beginners ...
Edureka!
 
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
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)

PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PPTX
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
community health nursing question paper 2.pdf
Prince kumar
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 

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