![]() |
VOOZH | about |
In this article, we are going to see how to create an empty vector in R Programming Language. There are five ways of creating an empty vector and each of them will be discussed in detail below:
Here in this, we need not pass anything while creating an empty vector as we are creating empty vector.
Syntax:
vector name <- c()
Where, vector name can be any valid identifier.
Example :
Output:
NULL
Output is null as we are not passing any data to it.
Here in this, we need not pass anything as we are creating an empty vector:
Syntax:
vector name <- vector()
Where, vector name can be any valid identifier.
Example
Output:
logical(0)
Output is empty as we are not passing any data.
Here we are creating empty vector by passing null.
Syntax:
vector name <- NULL
Where, vector name can be any valid identifier.
Example
Output:
NULL
Here we are creating empty vector by using numeric().
Syntax:
vector name <- numeric()
Where, vector name can be any valid identifier.
Example
Output:
numeric(0)
Here we can directly use rep() to create empty vector.
Syntax:
vector name<- rep()
where, vector name can be any valid identifier.
Example:
Output:
NULL