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?
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.
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.
To create an empty list in R programming, call list() function and pass no arguments in the function call.
You can use the c() function, vector() method, rep() or assign a NULL value to the existing vector or initialize the vector with NULL.
With recent versions of R, you have to supply the origin :
as.Date(x = integer(0), origin = "1970-01-01")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With