Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:39:03+00:00 2026-06-18T10:39:03+00:00

I have a daily time series data and wish to construct a daily moving

  • 0

I have a daily time series data and wish to construct a daily moving average and create a quarterly data frame. As an example the first data set (of the example data) should include daily data for the months January, February and March, while the second series should be February, March and April. Similarly, the last data set should be that of October, November and December. I wish to do this for the variables “tmpd, pm10median and so2median” in the sample data. How can I achieve this?

library(gamair) 
data(chicago) 
chicago$date<-seq(from=as.Date("1987-01-01"), to=as.Date("2000-12-31"),length=5114)
data<- chicago[,c("date","tmpd", "pm10median", "so2median" )]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:39:04+00:00Added an answer on June 18, 2026 at 10:39 am

    Using xts package , you can do something like this

    library(xts)
    dat.ts <- xts(x=data[,-1],                   ## create an xts object 
                  order.by=as.Date(data[,1]))    ## coerce the index to date
    dat.quart <- apply.quarterly(dat.ts,mean)    ## apply for each quarter
    

    To show some rows:

     rbind(head(dat.quart),tail(dat.quart))
                   tmpd pm10median  so2median
    1987-03-31 33.60556         NA         NA
    1987-06-30 62.19231         NA -0.3283393
    1987-09-30 71.31522         NA -1.9137842
    1987-12-31 41.09783         NA         NA
    1988-03-31 27.06593         NA         NA
    1988-06-30 60.48352         NA         NA
    1999-09-30 71.01087   2.697414 -0.4532943
    1999-12-31 42.86957   1.565251 -0.4035715
    2000-03-31 34.74725  -4.704813  0.2392453
    2000-06-30 59.07692         NA -0.5426823
    2000-09-30 69.67391         NA -1.9221470
    2000-12-31 36.59783         NA -0.2387025
    

    UPDATE

    It looks that the OP wants to split the Moving average series by quarter.

    dat.ts <- xts(x=data[,-1],                   ## create an xts object 
                  order.by=as.Date(data[,1]))    ## coerce the index to date
    dat.m <- rollmean(dat.ts,k=2)                ## compute the MA
    ep <- endpoints(dat.m, "quarters")           ## create an index
    ## this split the seriers by quarter
    xx <- sapply(1:(length(ep) - 1), function(y) { 
      dat.m[(ep[y] + 1):ep[y + 1]]
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some daily time-series data that i need to extract the 'week day
If I have data (a daily stock chart is a good example but it
I have a data frame of daily data: df with four columns: Date, A,
I have a database full of time-sensitive data, so on a daily basis I
I have daily time series (of working days) which I would like to transform
Assume you have a table with a stock time series on a daily basis.
I have a set of about 2000 separate time-series in the form of SortedList<DateTime,double>
I have the following data.frame in R: > daily DoW Duration 1 Friday 14.0000000000000
I have a daily cron job that grabs 10 users at a time and
I want to create a counter, daily, weekly and all time. Each product in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.