Basic data types
R Programming works with numerous data types, including
- Vectors (numerical, character, logical)
- Data frames
- 4.5 is a decimal value called numerics.
- 4 is a natural value called integers. Integers are also numerics.
- TRUE or FALSE is a Boolean value called logical.
- The value inside " " or ' ' are text (string). They are called characters.
We can check the type of a variable with the class function
# Declare variables of different types
x <- 28
##  "numeric"
y <- "R is Fantastic"
##  "character"
z <- TRUE
##  "logical"
Variables store values and are an important component in programming, especially for a data scientist. A variable can store a number, an object, a statistical result, vector, dataset, a model prediction basically anything R outputs. We can use that variable later simply by calling the name of the variable.
To declare a variable, we need to assign a variable name. The name should not have space. We can use _ to connect to words.
To add a value to the variable, use <- or =.
Here is the syntax:
# First way to declare a variable: use the `<-`
name_of_variable <- value
# Second way to declare a variable: use the `=`
name_of_variable = value
In the command line, we can write the following codes to see what happens:
# Print variable x
x <- 42
##  42
A vector is a one-dimensional array. We can create a vector with all the basic data type we learnt before. The simplest way to build a vector in R, is to use the c command.
vec_num <- c(1, 10, 49)
##  1 10 49