1

I have some data which I want to change to a weekly scale with the xts package, everything works fine except that the column names change in an undesirable way.

As you can see...

> head(x)
           Open High  Low Close Volume (BTC) Volume (Currency) Weighted Price
2011-09-13 5.80 6.00 5.65  5.97     58.37138          346.0974       5.929231
2011-09-14 5.58 5.72 5.52  5.53     61.14598          341.8548       5.590798
2011-09-15 5.12 5.24 5.00  5.13     80.14080          408.2590       5.094272
2011-09-16 4.82 4.87 4.80  4.85     39.91401          193.7631       4.854515
2011-09-17 4.87 4.87 4.87  4.87      0.30000            1.4610       4.870000
2011-09-18 4.87 4.92 4.81  4.92    119.81280          579.8431       4.839576
> x.weekly  <- to.weekly(x)
> head(x.weekly)
           x.Open x.High x.Low x.Close x.Volume
2011-09-18   5.80   6.00  4.80    4.90 379.6850
2011-09-25   4.92   6.06  4.80    4.80 313.7540
2011-10-02   4.85   4.92  0.00    4.87 184.9483
2011-10-09   4.86   6.25  3.89    4.51 721.2252
2011-10-16   3.98   4.10  0.00    3.92 374.4428
2011-10-23   0.00   2.99  0.00    2.92 167.9757

Is there any quick way to keep the intial column names, respectively? I have tried with to.weekly(x, names = "") but this gives the following names .Open, .High etc.

phiver
  • 23,048
  • 14
  • 44
  • 56
uncool
  • 2,613
  • 7
  • 26
  • 55

1 Answers1

2

Set name = NULL in the to.weekly call.

require(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
head(to.weekly(x))
#              x.Open   x.High    x.Low  x.Close
# 2007-01-07 50.03978 50.42188 49.95041 49.99185
# 2007-01-14 50.03555 50.62395 49.80454 50.60145
# 2007-01-21 50.61724 50.77336 50.02142 50.42090
# 2007-01-28 50.36008 50.43875 49.87468 49.88096
# 2007-02-04 49.85624 50.55509 49.76308 50.55509
# 2007-02-11 50.52389 50.91776 50.45977 50.91160
head(to.weekly(x, name=NULL))
#                Open     High      Low    Close
# 2007-01-07 50.03978 50.42188 49.95041 49.99185
# 2007-01-14 50.03555 50.62395 49.80454 50.60145
# 2007-01-21 50.61724 50.77336 50.02142 50.42090
# 2007-01-28 50.36008 50.43875 49.87468 49.88096
# 2007-02-04 49.85624 50.55509 49.76308 50.55509
# 2007-02-11 50.52389 50.91776 50.45977 50.91160
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418