Primitives in R

Find this useful? Support us: Star on GitHub 6
Category: Datatypes | Language: R

In R, there are five main primitive data types. These are:

1. Numeric: This data type represents numeric values. It includes positive and negative numbers, as well as decimal points. For example, x <- 7 or y <- 3.14.

2. Logical: This data type represents logical values. It includes TRUE and FALSE. For example, x <- TRUE or y <- FALSE.

3. Character: This data type represents characters and strings. It includes combinations of letters, digits and other characters. For example, x <- "hello, world!" or y <- "123".

4. Integer: This data type represents integer values. It includes positive and negative whole numbers. For example, x <- 10 or y <- -5.

5. Complex: This data type represents complex numbers, which are numbers with real and imaginary parts. For example, x <- 3 + 4i or y <- -6i.

Here are some examples of using these primitive types in R:

# Numeric
x <- 5
y <- 3.14159

# Logical
a <- TRUE
b <- FALSE

# Character
name <- "Rahul"
message <- "Hello, how are you?"

# Integer
age <- 28
siblings <- 3

# Complex
z <- 1 + 2i

It is important to note that R also has other data types such as lists, vectors, matrices and arrays which are built upon these primitive types.