Type to search

Coercion in R

To Know more about the Different Corporate Training & Consulting Visit our website www.Instrovate.com Or Email : info@instrovate.com or WhatsApp / Call at +91 74289 52788

Data Analytics R Programming

Coercion in R


Coercion :

Coercion includes type conversion . Type conversion means change of one type of data into another type of data. We have to type of coercion occurs :

 1. Implicit Coercion

 2. Explicit Coercion

Explicit Coercion :

In explicit coercion , we can change one data type to another data type by applying function.

We create an object “x” which stores integer values from 1 to 6.


We can check data type of “x” object.


We used as.numeric() to change integer data type to numeric data type.


We check data type of z. It shows “numeric” data type.


Coercion in R 29

We can also change character data to numeric data as:

Coercion in R 30

Coercion in R 31

We also changed logical data to character data.

Coercion in R 32

We also changed integer data to Logical data as:

Coercion in R 33

When we changed numeric or integer to logical data , it will store 0 as FALSE and other values as TRUE. You can see here also .

Coercion in R 34

Some exceptions of explicit coercion :-

Coercion in R 35

We are converting character data type to numeric data type. It will show NA . It will show missing in out object. It will not change character data to numeric because it includes values “a” which cannot be changed to numeric data.

Implicit Coercion :

When type conversion occurs by itself in R.

We input numeric and character data in an object . R converts numeric data to character data by itself.

Coercion in R 36

We input logical and numeric data in an object . Logical data convert to numeric data implicitly.

Coercion in R 37

There are many types of objects to store R-object . The frequently used objects are –

  • Vectors
  • Matrices
  • Arrays
  • Factors
  • Data Frames
  • Lists
  • Table