Home » R Programming Tutorial » R Data Types

R Data Types


Datatypes are the format in which the data is stored as a variable. The variables are
assigned to R-objects and data type of the R-object becomes the data type of the variable.

There are following R Objects

Vectors
Lists
Matrices
Arrays
Factors
DataFrames

These will be discussed in detail later.

R – Data Types

Numeric

x <- c(5,3,7,8)
print(x)

Output

[1] 5 3 7 8
print(class(x))

Output

## [1] "numeric"

Integer

x <- c(5,3,7,8)
x <- as.integer(x)
print(x)

Output

## [1] 5 3 7 8
print(class(x))

Output

## [1] "integer"

Complex

x <- 4+7i
print(x)

Output

## [1] 4+7i
print(class(x))

Output

## [1] "complex"

Character

x <- 'myname'
print(x)

Output

## [1] "myname"
print(class(x))

Output

## [1] "character"

Logical

x <- TRUE
print(x)

Output

## [1] TRUE
print(class(x))

Output

## [1] "logical"

Raw

x <- charToRaw("Hello World")
print(x)

Output

## [1] 48 65 6c 6c 6f 20 57 6f 72 6c 64
print(class(x))

Output

## [1] "raw"