R – Create an Empty Vector

In this tutorial, we will learn how to create an empty vector in R programming Language.

To create an empty vector in R, call c() function and pass no argument to it.

The syntax to create an empty vector x is

</>
Copy
x <- c()

Examples

Create Empty Vector

In this example, we create an empty vector using c() function.

Example.R

</>
Copy
x <- c()
print(x)

Output

NULL

An empty vector returns NULL when print to standard output.

Length of Empty Vector

Since there are no elements in the vector, the length must be zero, which we shall verify using length() function.

Example.R

</>
Copy
x <- c()
cat("Length of vector :", length(x))

Output

Length of vector : 0

Conclusion

In this R Tutorial, we learned how to create an empty vector in R, with the help of example programs.