rlubridater-rownames

How to properly assign row names to ("mts", "ts", "matrix") object in R?


I want to assign row names to a ("mts", "ts", "matrix") object:

library(lubridate)
library(zoo)
myVAR <- cbind(ts(rnorm(64,0,1)),ts(rnorm(64,0,1)),ts(rnorm(64,0,1)), ts(rnorm(64,0,1)))
class(myVAR) # "mts" "ts" "matrix"
dim(myVAR) # 64x4

as.yearmon(seq(ymd('2010-09-01'), by = '1 month', length.out=(64)))
# "Sep 2010" "Oct 2010" ...."Dec 2015"; I wanna assign these as row names

row.names(myVAR) <- as.yearmon(seq(ymd('2010-09-01'), by = '1 month', length.out=(64)))

The last assginment results in almost nothing:

myVAR

# Time Series:
Start = 1 
End = 64 
Frequency = 1 
ts(rnorm(64, 0, 1)) ts(rnorm(64, 0, 1)) ts(rnorm(64, 0, 1)) ts(rnorm(64, 0, 1))
1         0.082237617          0.18201849          0.54350780    -0.09849474
 2        -0.471237861          0.82705042          0.72799739 0.68516426
 3        -0.258811941          0.36791007         -1.68230838  0.35263624
....................................................................
64   -0.663503979         -0.06671596          0.16724293 -0.12728622

But, interestingly:

row.names(myVAR)
[1] "2010.66666666667" "2010.75"          "2010.83333333333" "2010.91666666667"
............................................................
[61] "2015.66666666667" "2015.75"          "2015.83333333333" "2015.91666666667"

As far as I see, this shows R made the rownames assignment, but wrongly. Why? Any idea?


Solution

  • J_F solved my problem:

    In my case, there were stationary and nonstationary variables. The nonstationary variables were made stationary upon differencing. These resulted in NAs at the beginning of the differenced series when these series are thought together with the already stationary ones. I applied:

    ts(ts.intersect(kur1f, lnbist1f, lnaltin, mfaiz1f), start = c(2010, 9), frequency = 12)
    

    and now rownames are just I want. Many many thanks to J_F again.

    For those who interested:
    kur1f: 1st difference of exchange rate
    lnbist1f: 1st difference of ln of BIST100 Stock Exchange
    lnaltin: ln of Gold prices
    mfaiz1f: 1st difference of interest rates