How to create a numeric vector of zero length in R

Surjya Narayana Padhi picture Surjya Narayana Padhi · Sep 27, 2012 · Viewed 203.4k times · Source

I wonder, how can I create a numeric zero-length vector in R?

Answer

mnel picture mnel · Sep 27, 2012

If you read the help for vector (or numeric or logical or character or integer or double, 'raw' or complex etc ) then you will see that they all have a length (or length.out argument which defaults to 0

Therefore

numeric()
logical()
character()
integer()
double()
raw()
complex() 
vector('numeric')
vector('character')
vector('integer')
vector('double')
vector('raw')
vector('complex')

All return 0 length vectors of the appropriate atomic modes.

# the following will also return objects with length 0
list()
expression()
vector('list')
vector('expression')