0

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?

M--
  • 25,431
  • 8
  • 61
  • 93
Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40
  • What is `myVAR`? Is it the third line of your code? But then `class(...)` should be `yearmon`. – J_F Oct 13 '16 at 07:45
  • @J_F myVAR is a ("mts" "ts" "matrix") object obtained via ts(a dataframe object). – Erdogan CEVHER Oct 13 '16 at 07:48
  • 1
    so then make your example a reproducible example! – J_F Oct 13 '16 at 07:49
  • @J_F I just did reproduciblity above. – Erdogan CEVHER Oct 13 '16 at 07:59
  • 1
    In my opinion you should use `myVAR <- ts(matrix(rnorm(256), 64, 4), start = c(2010, 9), frequency = 12)` then automatically all the rownames are as you expect them, or? – J_F Oct 13 '16 at 08:03
  • Thanks a lot J-F. It solved. In my case, there were stationary and nonstationary variables. And upon your advice, I made `ts(ts.intersect(kur1f, lnbist1f, lnaltin, mfaiz1f), start = c(2010, 9), frequency = 12)`and now rownames are just I want. Many many thanks again. – Erdogan CEVHER Oct 13 '16 at 08:08

1 Answers1

0

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

Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40