Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: How to extract dates from a time series

How can I extract dates from a times series? Here is a time series:

x = seq (1, 768) myts <- ts(x, start=1982, frequency=24) 

Originally I needed to create a vector holding date/time data for the rts function, The observations start 1982 with 2 measurements per month going till 2013.

like image 218
Liza Avatar asked Mar 23 '15 01:03

Liza


People also ask

How do I get dates in R?

In R programming, if you use Sys. Date() function, it will give you the system date. You don't need to add an argument inside the parentheses to this function.

How do I extract a date from POSIXct in R?

To get the year from a date in R you can use the functions as. POSIXct() and format() . For example, here's how to extract the year from a date: 1) date <- as. POSIXct("02/03/2014 10:41:00", format = "%m/%d/%Y %H:%M:%S) , and 2) format(date, format="%Y") .

How do I extract the day from a date in R?

If you just want the day as a string, you can use format(as. Date(df$x,format="%Y-%m-%d"), "%d") .


1 Answers

Try:

time(myts) 

or perhaps:

library(zoo) as.yearmon(time(myts)) 
like image 112
G. Grothendieck Avatar answered Sep 22 '22 23:09

G. Grothendieck