Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an empty vector of dates?

Tags:

r

vector

Is it possible to create an empty vector of dates in r?

I can create an empty vector of integers, doubles, logicals etc:

> integer()
integer(0)
> double()
numeric(0)
> logical()
logical(0)
> length(integer())
[1] 0

but this meme doesn't work for dates, as date() returns the current system date and time. So, how would I create an emtpy vector of dates?

like image 364
René Nyffenegger Avatar asked Jun 20 '15 19:06

René Nyffenegger


People also ask

How do you get an empty vector in R?

Create Empty Vector using c() One of the most used way to create a vector in R is by using c() combined function. Use this c() function with out any arguments to initialize an empty vector. Use length() function to get the length of the vector. For empty vector the length would be 0.

How do you create an empty vector of length n in R?

To create a vector of specified data type and length in R we make use of function vector(). vector() function is also used to create empty vector.

How do I create an empty set in R?

To create an empty list in R programming, call list() function and pass no arguments in the function call.

How do I initialize a null vector in R?

You can use the c() function, vector() method, rep() or assign a NULL value to the existing vector or initialize the vector with NULL.


1 Answers

With recent versions of R, you have to supply the origin :

as.Date(x = integer(0), origin = "1970-01-01")
like image 191
PAC Avatar answered Oct 01 '22 05:10

PAC