How to Create a Vector of Zero Length in R
Last Updated :
23 Aug, 2021
In this article, we are going to discuss how to create a vector of zero length in R programming language.
We can create a vector of zero length by passing the datatype as a value to the vector.
Syntax:
vector=datatype()
There are six data types and each can be used to create a vector of the required datatype. Let’s see how to create a vector of 0 length of each data type.
character()
It is used to create a Numeric vector of 0 length.
Syntax:
vector = character()
Example: R program to create a numeric vector of 0 length and display
R
vector < - character ()
print (vector)
|
Output:
character(0)
factor()
It is used to create a Factor vector of 0 length
Syntax:
vector = factor()
Example: R program to create a factor vector of length 0 and display
R
vector = factor ()
print (vector)
|
Output:
factor(0)
Levels:
logical()
It is used to create a logical vector of 0 length.
Syntax:
vector = logical()
Example: R program to create a logical vector of length 0 and display
R
vector = logical ()
print (vector)
|
Output:
logical(0)
integer()
It is used to create an Integer vector of 0 length.
Syntax:
vector = integer ()
Example: R program to create an integer vector of length 0 and display
R
vector = integer ()
print (vector)
|
Output:
integer(0)
double()
It is used to create a double vector of 0 length.
Syntax:
vector = double()
Example: R program to create a double vector of 0 length and display
R
vector = double ()
print (vector)
|
Output:
numeric(0)
raw()
It is used to create a raw vector of 0 length.
Syntax:
vector = raw()
Example: R program to create a Raw vector of length 0 and display
R
vector = raw ()
print (vector)
|
Output:
raw(0)
complex()
It is used to create a complex vector of 0 length.
Syntax:
vector = complex()
Example: R program to create a complex vector of 0 length and display
R
vector = complex ()
print (vector)
|
Output:
complex(0)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...