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 4109822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:51:06+00:00 2026-05-20T21:51:06+00:00

Following up my previous question about aggregating hourly data into daily data, I want

  • 0

Following up my previous question about aggregating hourly data into daily data, I want to continue with (a) monthly aggregate and (b) merging the monthly aggregate into the original dataframe.

My original dataframe looks like this:

Lines <- "Date,Outdoor,Indoor
01/01/2000 01:00,30,25
01/01/2000 02:00,31,26
01/01/2000 03:00,33,24
02/01/2000 01:00,29,25
02/01/2000 02:00,27,26
02/01/2000 03:00,39,24
12/01/2000 02:00,27,26
12/01/2000 03:00,39,24
12/31/2000 23:00,28,25"

The daily aggregates have been answered in my previous question, and then I can find my way to produce the monthly aggregates from there, to something like this:

Lines <- "Date,Month,OutdoorAVE
01/01/2000,Jan,31.33
02/01/2000,Feb,31.67
12/01/2000,Dec,31.33"

Where the OutdoorAVE is the monthly average of the daily minimum and maximum outdoor temperature. What I want to have in the end is something like this:

Lines <- "Date,Outdoor,Indoor,Month,OutdoorAVE
01/01/2000 01:00,30,25,Jan,31.33
01/01/2000 02:00,31,26,Jan,31.33
01/01/2000 03:00,33,24,Jan,31.33
02/01/2000 01:00,29,25,Feb,31.67
02/01/2000 02:00,27,26,Feb,31.67
02/01/2000 03:00,39,24,Feb,31.67
12/01/2000 02:00,27,26,Dec,31.33
12/01/2000 03:00,39,24,Dec,31.33
12/31/2000 23:00,28,25,Dec,31.33"

I do not know enough R on how to do that. Any help is greatly appreciated.

  • 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-20T21:51:07+00:00Added an answer on May 20, 2026 at 9:51 pm

    Try ave and eg POSIXlt to extract the month:

    zz <- textConnection(Lines)
    Data <- read.table(zz,header=T,sep=",",stringsAsFactors=F)
    close(zz)
    
    Data$Month <- strftime(
         as.POSIXlt(Data$Date,format="%m/%d/%Y %H:%M"),
         format='%b')
    Data$outdoor_ave <- ave(Data$Outdoor,Data$Month,FUN=mean)
    

    Gives :

    > Data
                  Date Outdoor Indoor Month outdoor_ave
    1 01/01/2000 01:00      30     25   Jan    31.33333
    2 01/01/2000 02:00      31     26   Jan    31.33333
    3 01/01/2000 03:00      33     24   Jan    31.33333
    4 02/01/2000 01:00      29     25   Feb    31.66667
    5 02/01/2000 02:00      27     26   Feb    31.66667
    6 02/01/2000 03:00      39     24   Feb    31.66667
    7 12/01/2000 02:00      27     26   Dec    31.33333
    8 12/01/2000 03:00      39     24   Dec    31.33333
    9 12/31/2000 23:00      28     25   Dec    31.33333
    

    Edit : Then just calcualte Month in Data as shown above and use merge :

    zz <- textConnection(Lines2) # Lines2 is the aggregated data
    Data2 <- read.table(zz,header=T,sep=",",stringsAsFactors=F)
    close(zz)
    
    > merge(Data,Data2[-1],all=T)
      Month             Date Outdoor Indoor OutdoorAVE
    1   Dec 12/01/2000 02:00      27     26      31.33
    2   Dec 12/01/2000 03:00      39     24      31.33
    3   Dec 12/31/2000 23:00      28     25      31.33
    4   Feb 02/01/2000 01:00      29     25      31.67
    5   Feb 02/01/2000 02:00      27     26      31.67
    6   Feb 02/01/2000 03:00      39     24      31.67
    7   Jan 01/01/2000 01:00      30     25      31.33
    8   Jan 01/01/2000 02:00      31     26      31.33
    9   Jan 01/01/2000 03:00      33     24      31.33
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following my previous question , i have a question about why is it this
Following on from my previous question , is it possible to make a Python
Following on from my previous question [link text][1] , I have a new problem.
In a comment on a previous question, someone said that the following sql statement
Following Izb's question about Best binary XML format for JavaME , I'm looking for
Following on from a previous question , I've been playing around with optimizer settings
As in my previous question I have the following problem. I have a matrix
Following on from my recent question on Large, Complex Objects as a Web Service
Following my question regarding a .NET YAML Library ... as there doesn't seem to
Following this question: Good crash reporting library in c# Is there any library like

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.