I have a data object called NKLA
that looks like this:
> class(NKLA)
[1] "xts" "zoo"
> head(NKLA)
NKLA.Open NKLA.High NKLA.Low NKLA.Close NKLA.Volume NKLA.Adjusted
2018-06-11 9.57 9.58 9.57 9.58 402600 9.58
2018-06-12 9.56 9.56 9.56 9.56 300000 9.56
2018-06-13 9.57 9.58 9.56 9.57 179100 9.57
2018-06-14 9.57 9.57 9.57 9.57 0 9.57
2018-06-15 9.57 9.57 9.57 9.57 0 9.57
2018-06-18 9.54 9.58 9.54 9.58 300 9.58
But when I try to convert it to data.frame like
- this as suggested here:
data.frame(date=index(NKLA), coredata(NKLA))
- or this, suggested here:
as.data.table(NKLA)
- or this, suggested here:
as.data.frame.matrix(NKLA)
- but I also found this:
as.data.frame.table(NKLA)
- and this:
as.data.table(NKLA)
- and this too:
as.data.frame(NKLA)
I each time get an [1] "xts" "zoo"
to the query class(NKLA)
.
My question:
- How do I convert an
xts
/zoo
object into adata.frame
object?
Any help appreciated.
System used:
- R version: 4.1.1 (2021-08-10)
- RStudio version: 1.4.1717
- OS: macOS Catalina version 10.15.7