can i keep the same datatype(zoo)
and date index when i write.csv and read.csv for the tseries library of R instant of change the datatype to dataframe, actually i want to save to zoo format and retrieve also keep to same format with date indexing. from tseries
library of R
Rcode
library("tseries")
a = get.hist.quote(instrument="VBIRX", start="2022-01-01",
end="2022-03-01", quote="AdjClose",
provider="yahoo", compression="m", ret)
datatype for a
class(a)
a
(a)data
'zoo'
Adjusted
2022-01-01 10.38586
2022-02-01 10.32541
when i save in csv format
write.csv(a,"a.csv")
b = read.csv("a.csv")
datatype for b read.csv form file
class(b)
b
(b)data after read.csv from file
'data.frame'
A data.frame: 2 × 2
X Adjusted
<int> <dbl>
1 10.38586
2 10.32541
CodePudding user response:
csv is not the right format to save this data. You may try saving it in rds file.
library(tseries)
a = get.hist.quote(instrument="VBIRX", start="2022-01-01",
end="2022-03-01", quote="AdjClose",
provider="yahoo", compression="m", ret)
a
# Adjusted
#2022-01-01 10.38586
#2022-02-01 10.32542
class(a)
#[1] "zoo"
saveRDS(a, 'a.rds')
b <- readRDS('a.rds')
b
# Adjusted
#2022-01-01 10.38586
#2022-02-01 10.32542
class(b)
#[1] "zoo"