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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:38:03+00:00 2026-06-06T17:38:03+00:00

This is the data in my text file: (I have shown 10 rows out

  • 0

This is the data in my text file: (I have shown 10 rows out of 10,000)
Index is the rownames, temp is time series and m are the values in mm.

     "Index" "temp" "m"
   1 "2012-02-07 18:15:13" "4297"
   2 "2012-02-07 18:30:04" "4296"
   3 "2012-02-07 18:45:10" "4297"
   4 "2012-02-07 19:00:01" "4297"
   5 "2012-02-07 19:15:07" "4298"
   6 "2012-02-07 19:30:13" "4299"
   7 "2012-02-07 19:45:04" "4299"
   8 "2012-02-07 20:00:10" "4299"
   9 "2012-02-07 20:15:01" "4300"
   10 "2012-02-07 20:30:07" "4301"

Which I import in r using this:

    x2=read.table("data.txt", header=TRUE)

I tried using the following code for aggregating the time series to daily data :

   c=aggregate(ts(x2[, 2], freq = 96), 1, mean)

I have set the frequency to 96 because for 15 min data 24 hrs will be covered in 96 values.

it returns me this:

    Time Series:
   Start = 1 
   End = 5 
   Frequency = 1 
   [1] 5366.698 5325.115 5311.969 5288.542 5331.115

But i want the same format in which I have my original data i.e. I also want the time series next to the values.
I need help in achieving that.

  • 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-06T17:38:04+00:00Added an answer on June 6, 2026 at 5:38 pm

    Use the apply.daily from the xts package after converting your data to an xts object:

    Something like this should work:

    x2 = read.table(header=TRUE, text='     "Index" "temp" "m"
    1 "2012-02-07 18:15:13" "4297"
    2 "2012-02-07 18:30:04" "4296"
    3 "2012-02-07 18:45:10" "4297"
    4 "2012-02-07 19:00:01" "4297"
    5 "2012-02-07 19:15:07" "4298"
    6 "2012-02-07 19:30:13" "4299"
    7 "2012-02-07 19:45:04" "4299"
    8 "2012-02-07 20:00:10" "4299"
    9 "2012-02-07 20:15:01" "4300"
    10 "2012-02-07 20:30:07" "4301"')
    
    x2$temp = as.POSIXct(strptime(x2$temp, "%Y-%m-%d %H:%M:%S"))
    require(xts)
    x2 = xts(x = x2$m, order.by = x2$temp)
    apply.daily(x2, mean)
    ##                       [,1]
    ## 2012-02-07 20:30:07 4298.3
    

    Update: Your problem in a reproducable format (with fake data)

    We don’t always need the actual dataset to be able to help troubleshoot….

    set.seed(1) # So you can get the same numbers as I do
    x = data.frame(datetime = seq(ISOdatetime(1970, 1, 1, 0, 0, 0), 
                                  length = 384, by = 900), 
                   m = sample(2000:4000, 384, replace = TRUE))
    head(x)
    #              datetime    m
    # 1 1970-01-01 00:00:00 2531
    # 2 1970-01-01 00:15:00 2744
    # 3 1970-01-01 00:30:00 3146
    # 4 1970-01-01 00:45:00 3817
    # 5 1970-01-01 01:00:00 2403
    # 6 1970-01-01 01:15:00 3797
    require(xts)
    x2 = xts(x$m, x$datetime)
    head(x2)
    #                     [,1]
    # 1970-01-01 00:00:00 2531
    # 1970-01-01 00:15:00 2744
    # 1970-01-01 00:30:00 3146
    # 1970-01-01 00:45:00 3817
    # 1970-01-01 01:00:00 2403
    # 1970-01-01 01:15:00 3797
    apply.daily(x2, mean)
    #                         [,1]
    # 1970-01-01 23:45:00 3031.302
    # 1970-01-02 23:45:00 3043.250
    # 1970-01-03 23:45:00 2896.771
    # 1970-01-04 23:45:00 2996.479
    

    Update 2: A workaround alternative

    (Using the fake data I’ve provided in the above update.)

    data.frame(time = x[seq(96, nrow(x), by=96), 1],
               mean = aggregate(ts(x[, 2], freq = 96), 1, mean))
    #               time     mean
    # 1 1970-01-01 23:45 3031.302
    # 2 1970-01-02 23:45 3043.250
    # 3 1970-01-03 23:45 2896.771
    # 4 1970-01-04 23:45 2996.479
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have text stored in SQL as HTML. I'm not guaranteed that this data
I have multiple text files with logged data like this: 6/23/09 17:00 0.443 6/23/09
I have a JSON array as shown below : [{id:1,text: Hi this is text
I have a text file having some data in following format %app_lookup_strings = (
Using the snippet below, I've attempted to extract the text data from this PDF
What's wrong with this function: function() { $.get('/controller/action', function(data) { $('#temporaryPhotos').text(data); } ); return
I am parsing data from this XML url The text input varies, depending on
I have this array {$man_data} which is structured like 10 > 'Text 8' 14
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
I have a csv reader class that reads a .csv file and its values....

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.