0

I am having problems accessing the timestamp of my xts object in R.

The structure of the object looks like this

                    FB.Open FB.High FB.Low FB.Close FB.Volume  FB.WAP FB.hasGaps FB.Count
2015-10-30 10:40:00  104.61  104.62 104.35   104.38      4532 104.472          0     2067

I have no problems accessing FB.Open, FB.High, etc.

I am doing so by calling data[1,1] for example and would get the following

                    FB.Open
2015-10-30 10:30:00  104.38

The problem is when I try to access the index

For example, when I do something like

data[1,0]

I would get

2015-10-30 10:30:00

I get an xts object with zero-width which I can't seem to manipulate.

I simply need to put the timestamp inside a variable.

Any tip in the right direction will be appreciated.

Thanks

JordanBelf
  • 3,208
  • 9
  • 47
  • 80

1 Answers1

3

Use index(xtsobject)

data(sample_matrix)
sample.xts <- as.xts(sample_matrix, descr='my new xts object')
index(sample.xts)

> index(sample.xts)
  [1] "2007-01-02 EST" "2007-01-03 EST" "2007-01-04 EST" "2007-01-05 EST" "2007-01-06 EST" "2007-01-07 EST"
  [7] "2007-01-08 EST" "2007-01-09 EST" "2007-01-10 EST" "2007-01-11 EST" "2007-01-12 EST" "2007-01-13 EST"
 [13] "2007-01-14 EST" "2007-01-15 EST" "2007-01-16 EST" "2007-01-17 EST" "2007-01-18 EST" "2007-01-19 EST"
 [19] "2007-01-20 EST" "2007-01-21 EST" "2007-01-22 EST" "2007-01-23 EST" "2007-01-24 EST" "2007-01-25 EST"
Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56