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

  • Home
  • SEARCH
  • 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 6751997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:35+00:00 2026-05-26T12:59:35+00:00

I have a problem and would really need your help? My data (let’s name

  • 0

I have a problem and would really need your help? My data (let’s name it “date”) looks like this:

location       date  value
       1 2010-01-01    6.4
       1 2010-01-02    5.7
       .
       .  
       2 2010-01-01    0.8
       2 2010-01-02    2.5
       2 2010-01-03    5.5

I would like to aggregate data (value) on location and on 3 weeks period? I have already try to use package timeSeries but it is not working?

by1 <- timeSequence(from = "2009-12-30", to = "2010-12-29", by= "4 week")
by1
aggregate(date, by=list(by1, date$location), sum)
  • 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-05-26T12:59:36+00:00Added an answer on May 26, 2026 at 12:59 pm

    Here is an approach using seq.Date to generate the break points, cut to bin your data, and ddply to summarize:

    # Create sample data
    set.seed(1)
    dat <- data.frame(
      location = rep(1:3, each=30),
      date = rep(seq(as.Date("2010-01-01"), by="3 day", length.out=30), 3),
      value=rnorm(90)
    )
    
    # Create a sequence of dates in period of 3 weeks ot serve as cut points
    dateCuts <- seq(from=min(dat$date), to=max(dat$date)+31, by="3 week")
    
    # Use cut to separate dates into periods
    dat$period <- cut(dat$date, breaks=dateCuts)
    
    # Summarise data
    library(plyr)
    ddply(dat, .(location, period), summarize, value=mean(value))
    

    The results:

       location     period       value
    1         1 2010-01-01  0.04475859
    2         1 2010-01-22  0.01062880
    3         1 2010-02-12  0.62024902
    4         1 2010-03-05 -0.31364304
    5         1 2010-03-26 -0.03010425
    6         2 2010-01-01 -0.08522653
    7         2 2010-01-22  0.37708986
    8         2 2010-02-12  0.12910449
    9         2 2010-03-05  0.08597110
    10        2 2010-03-26  0.21733251
    11        3 2010-01-01  0.10295425
    12        3 2010-01-22  0.46194453
    13        3 2010-02-12 -0.35546029
    14        3 2010-03-05  0.17216486
    15        3 2010-03-26  0.31855880
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would really appreciate if you could shed light on this problem. I have
I have a problem finding references to this subject and would appreciate some help.
Afternoon all, I really need your help as this is a Nightmare! I was
I've some questions .. and I really need your help. I have an application.
I have an interesting problem and would appreciate your thoughts for the best solution.
I have a problem and i would like to learn the correct way to
I have a problem that I would like have solved via a SQL query.
have small problem, and would very much appreciate help :) I should convert byte
I have a little problem where I would like to insert a svn diff
I have a reasonably complex layout problem: I would like to have a main

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.