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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:30:50+00:00 2026-05-31T01:30:50+00:00

I have a hourly dataset from 1996 – 2010 in the following format: date

  • 0

I have a hourly dataset from 1996 – 2010 in the following format:

             date         value  
1- - -1996-01-01 00:00:00- - -  NA  
2- - -1996-01-01 01:00:00- - -  38  
3 - - -1996-01-01 02:00:00- - - 44  
4- - -1996-01-01 03:00:00- - -  48  
5- - -1996-01-01 04:00:00- - -  42  
6- - -1996-01-01 05:00:00- - -  44  
7- - - 1996-01-01 06:00:00- - - 38  
8- - - 1996-01-01 07:00:00- - - 42  
9- - -1996-01-01 08:00:00- - -  44  
10- - -1996-01-01 09:00:00- - - 44  

I have lot of missing hours data and I am tring to calculate the missing hour values by taking the average of previous and next hour, and if many hours missing I am trying to calculate by taking the average of that hour for every day that year, just wondering if this is possible?

I have tried the following but this gives me average of the complete dataset:

a = c(NA, 1, 2, 3, 10)   
a[which(is.na(a)==TRUE)] = mean(a,na.rm = T)

I would really appreciate any advice about how I should proceed with this calculation.

  • 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-31T01:30:51+00:00Added an answer on May 31, 2026 at 1:30 am

    You could probably do this using some handy function from the zoo package. For instance, na.approx, with maxgap = 1 should linearly interpolate all the gaps of length one. Then you’d probably want to use na.aggregate, splitting by year and hour, to fill longer gaps with that periods’ mean.

    Here’s a simple example to give you a sense of how these functions work:

    set.seed(124)
    tt <- as.POSIXct("2000-01-01 10:00:00") + 3600*c(1:100,10000:10100)
    dd <- runif(201)
    
    aa <- data.frame(x1 = tt,x2 = dd)
    aa$x2[sample(201,30)] <- NA
    aa$x3 <- na.approx(aa$x2,maxgap = 1)
    aa$x4 <- na.aggregate(aa$x3,by = format(aa$x1,"%Y-%H"))
    

    Note that if your series has leading or trailing NAs, you might get errors, since the “linear interpolation” piece doesn’t make much sense in that case. So you’d have to fill those in some other way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an hourly weather data in the following format: Date,DBT 01/01/2000 01:00,30 01/01/2000
I have hourly weather data. I've seen the function examples from here: http://casoilresource.lawr.ucdavis.edu/drupal/node/991 I'm
I have the following tables (simplified): hours hour_rates - user_id - user_id - date
Folks, I have an hourly temperature data like this Lines <- Date,Outdoor,Indoor 01/01 01:00:00,24.5,21.3
(R beginner here...) I have a dataset like: > head(q) Date Time System User
I have the following script for importing text files into matlab which include hourly
I have a table with the following fields: Action => Click/Open DateTime => Date
I want to extract some hourly data from rrdtool databases in order to create
I have some hourly acquired data files. They filenames look like: 20120101-00.raw 20120101-01.raw ...
I have a database backup running hourly between 7am and 7pm everyday, each file

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.