# R Data Types

In this tutorial you will learn about the R Data Types and its application with practical example.

## R Data Types

Variables are used to represent reserved memory locations that is used to store values, when we create a variable we are a suppose to allocate some memory space for that variable. A variables always have a specific type and that type cannot change. Every variable have data type associated to it, the data type for a variable defines –

• The amount of memory space allocated for variables.
• A data type specifies the possible values for variables.
• The operations that can be performed on variables.

R comes with following built-in data types –

• Numeric
• Integer
• Complex
• Logical
• Character

R Numeric:- A variable with numeric data type is used to hold decimal values, if a decimal value is assigned to any variable then it will be referred to as numeric type.

Example:-

In R, even if we assign an integer value to a variable, it will still saved as a numeric type.

Example:-

R Integer:- Integers are used to store whole numbers. In R, an integer variable can be created using as.integer function, and integer data type can be verified using is.integer function.

Example:-

Any numeric value passed to as.integer function is coerce into an integer value

Example:-

R Complex:- R supports additional types for representing complex numbers (numbers with imaginary parts), to represent their real and imaginary parts. A complex value in R can be defined with pure imaginary value i.

Example:- Complex number can be defined as following –

In R, as.complex function can also be used to coerce value to complex number.

R Logical:- The logical data type is used to represent the truth values, which can be either True or False. Logical are commonly created via comparison between variables.

Example:-

R Character:- A character variable is used to hold single or series of characters – letters, numbers, and special characters. It can be declared using double quotes “Hello World”.

Example:-

In R, as.character function can also be used to coerce value to character.

In this tutorial we have learn about the R Data Types and its application with practical example. I hope you will like this tutorial.