Cannot save data when using summarize

Hi guys,

I'm doing some research on government bond yields, and therefore I need to aggregate my data from daily data to quarterly date (already done, see code below). My problem is, i cannot figure out, how to store the data ( or show in full format), once I have used the 'summarize'

Any help much appreciated

Best regards,

Code here:

library(dplyr)

library(readxl)
LW_daily <- read_excel("LW_daily.xlsx", sheet = "daily_adj", )

View(LW_daily)

#convert data

dat <- tibble(time=as.integer(format(as.Date("1971-01-04"), format="%Y%m%d")), LW_daily[3:360])

dat

dat |>
mutate(
time = as.Date(as.character(LW_daily$time), format="%Y%m%d"),
year = format(time, format = "%Y"),
qtr = lubridate::quarter(time)
) |>

summarize(.by = c(year, qtr), across(everything(LW_daily[3:360]), ~ mean(.x)))

I'm not sure I understand your problem, If you change the last part of your code to

Summary_Dat <- dat |>
mutate(
time = as.Date(as.character(LW_daily$time), format="%Y%m%d"),
year = format(time, format = "%Y"),
qtr = lubridate::quarter(time)
) |>
summarize(.by = c(year, qtr), across(everything(LW_daily[3:360]), ~ mean(.x)))

you will have a data frame named Summary_Dat that you can save with the save() function.

save(Summary_Dat, file = "Summary_Dat.Rdata")

Is that what you need of do you want to save it in some particular format? What do you mean by "show in full format"?

Hi again,

Actually, I think i solved it a few minutes ago after I made this post; I just added a variable name in front of dat, like you did with 'Summary_dat'

So, problem fixed!

Thanks for your reply

Best regards :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.