0

My data frame looks like that (with more columns and rows):

DT 
           Date PERMNO lag.ME.Jun
  <S3: yearmon> <fctr>      <dbl>
1      Gen 2000  34936     21.860
2      Feb 2000  34936     21.860
3      Mar 2000  34936     21.860

Then I create different time series for each column (for the variable lag.ME.Jun, for example):

v6<-xts( newdata11$lag.ME.Jun, newdata11$Date)

However, it adds also the date and time inside the time series; which was not provided. So v6 looks like:

                    34936
2000-01-01 01:00:00 21.86
2000-02-01 01:00:00 21.86
2000-03-01 01:00:00 21.86 

How can I avoid to have the day and time in the time to appear in the time series? only the month and year.

1 Answers1

0

It seems newdata11$Date is either a POSIXct type, or being converted to one. If yearmon is what you want, be explicit about it:

v6<-xts( newdata11$lag.ME.Jun, as.yearmon(newdata11$Date))

E.g.

d = as.yearmon(c("mar07", "apr07", "may07"), "%b%y")
> d
[1] "Mar 2007" "Apr 2007" "May 2007"
> xts(1:3, d)
         [,1]
Mar 2007    1
Apr 2007    2
May 2007    3
> d2= as.Date(c("2017-05-01", "2017-06-01", "2017-07-01"))
> xts(1:3, as.yearmon(d2))
         [,1]
May 2017    1
Jun 2017    2
Jul 2017    3
Darren Cook
  • 27,837
  • 13
  • 117
  • 217