Data Types in R

R has five main data types.

  1. Character
  2. Complex
  3. Integer
  4. Logical
  5. Numeric
    • Real
    • Decimal


Syntax for declaring variables in R :

# declaring a variable using `<-`
nameOfVariable <- value
# declaring a variable using `=`
nameOfVariable = value

Below is code declare variables of different types


# Variables of different types

# Character
myCharacter <- “B”
class(myCharacter)

#Complex
myComplex <- 9i
class(myComplex)

# Integer
myInteger <- 0:9
class(myInteger)

# Logical
myBoolean <- TRUE
class(myBoolean)

# Real Numeric
myRealNumeric <- 9
class(myRealNumeric)

# Decimal Numeric
myDecimalNumeric <- 9.0
class(myDecimalNumeric)

OUTPUT OF CODE :

[1] “character”
[1] “complex”
[1] “integer”
[1] “logical”
[1] “numeric”
[1] “numeric”

Leave a Reply

%d bloggers like this: