[This article was first published on R in Trevor French on Medium, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

There are five basic data types in R:

1. Numeric — This is the default treatment for numbers. This data type includes integers and doubles.
• Double — A double allows you to store numbers as decimals. This is the default treatment for numbers.
• Integer — An integer is a subset of the numeric data type. This type will only allow whole numbers and is denoted by the letter “L”.

2. Complex — This type is created by using the imaginary variable “i”.

3. Character — This type is used for storing non-numeric text data.

4. Logical — Sometimes referred to as “boolean”, this data type will store either “TRUE” or “FALSE”.

5. Raw — Used less often, this data type will store data as raw bytes.

### Numeric

Double

Let’s explore the “double” data type by assigning a number to a variable and then check it’s type by using the “typeof” function. Alternatively, we can use the “is.double” function to check whether or not the variable is a double.

```x <- 6.2
typeof(x)
#  "double"
is.double(x)
#  TRUE```

Next, let’s check whether or not the variable is numeric by using the “is.numeric” function.

```is.numeric(x)
#  TRUE```

This function should return “TRUE” as well, which demonstrates the fact that a double is a subset of the numeric data type.

Integer

Let’s explore the “integer” data type by assigning a whole number followed by the capital letter “L” to a variable and then check it’s type by using the “typeof” function. Alternatively, we can use the “is.integer” function to check whether or not the variable is an integer.

```x <- 6L
# By using the "typeof" function, we can check the data type of x
typeof(x)
#  "integer"
is.integer(x)
#  TRUE```

Next, let’s check whether or not the variable is numeric by using the “is.numeric” function.

```is.numeric(x)
#  TRUE```

This function should return “TRUE” as well, which demonstrates the fact that an integer is also a subset of the numeric data type.

### Complex

Complex data types make use of the mathematical concept of an imaginary number through the use of the lowercase letter “i”. The following example sets “x” equal to six times i and then displays the type of x.

```x <- 6i
typeof(x)
#  "complex"```

### Character

Character data types store text data. When creating characters, make sure you wrap your text in quotation marks.

```x <- "Hello!"
typeof(x)
#  "character"```

### Logical

Logical data types store either “TRUE” or “FALSE”. Unlike characters, these data should not be wrapped in quotation marks.

```x <- TRUE
typeof(x)
#  "logical"```

### Raw

Used less often, the raw data type will store data as raw bytes. You can convert character data types to raw data types by using the “charToRaw” function. Similarly, you can convert integer data types to raw data types through the use of the “intToBits” function.

```x <- charToRaw("Hello!")
print(x)
#  48 65 6c 6c 6f 21
typeof(x)
#  "raw"
x <- intToBits(6L)
print(x)
#  00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
#  00 00 00 00 00 00 00
typeof(x)
#  "raw"```
This is an excerpt from “R for Data Analysis” written by me. You can read the full book here: https://trevorfrench.github.io/R-for-Data-Analysis/ Data Types in R was originally published in Trevor French on Medium, where people are continuing the conversation by highlighting and responding to this story.