MAHMUT ZEKİ AKARSU
MAHMUT ZEKİ AKARSU

Reputation: 1

Exporting Data Frame to Excel in R

enter image description hereI try to export the data (which I got by coding from Yahoo). I can export data, but the date part does not go through, only the value part goes through. How can I export the date and value together to excel.

#Code:

library(tseries)
library(prophet)
library(tidyverse)
library(writexl)
library(readxl)

#determine date
start = "2013-01-01"
end = "2021-05-25"

#get the data from sources
TL <- get.hist.quote(instrument = "TRYUSD=X",
                          start = start,
                          end = end,
                          quote = "Close",
                          compression = "d")

#change the format of the dataset
y <- data.frame(TL)

#convert dataframe to excel document
write_xlsx(y,"C:/Users/hay/OneDrive/Desktop/Turkish Lira Forecast/TL.xlsx")#Load the dataset

#upload the dataset from excel file
bitcoin <- read_excel("C:/Users/hay/OneDrive/Desktop/bitcoin.xlsx")
View(bitcoin)

#call the prophet function to fit the model
model <- prophet(TL)
future <- make_future_dataframe(model, periods = 365)
tail(future)

#forecast
forecast <- predict(model, future)
tail(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper')])

#plot the model estimates

dyplot.prophet(model, forecast)

prophet_plot_components(model, forecast)

Upvotes: 0

Views: 2738

Answers (2)

akrun
akrun

Reputation: 887118

We can use

library(dplyr)
library(tibble)
y %>%
   rownames_to_column('Date') %>%
   writexl::write_xlsx("data.xlsx")

Upvotes: 2

Ronak Shah
Ronak Shah

Reputation: 388982

The date part can be extracted from the rownames -

y$Date <- rownames(y)
writexl::write_xlsx(y,"data.xlsx")

Upvotes: 1

Related Questions