joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 70 forks source link

as.xts.data.frame drops column name for data.frame with 1 non-time-based column #391

Closed joshuaulrich closed 1 year ago

joshuaulrich commented 1 year ago

No column name for data.frames with one column (other than the time-based column). Works correctly for more than non-time-based column.

require(xts)
packageVersion("xts")
## [1] '0.13.0'

x <- data.frame(Index = as.Date("2023-02-21"), Value = 21)
as.xts(x)
##            [,1]
## 2023-02-21   21

y <- data.frame(Index = as.Date("2023-02-21"), A = 21, B = 42)
as.xts(y)
##             A  B
## 2023-02-21 21 42