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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:20:41+00:00 2026-06-07T03:20:41+00:00

I have some observed data by hour. I am trying to subset this data

  • 0

I have some observed data by hour. I am trying to subset this data by the day or even week intervals. I am not sure how to proceed with this task in R.

The sample of the data is below.

date                                 obs
2011-10-24 01:00:00                  12
2011-10-24 02:00:00                  4
2011-10-24 19:00:00                  18
2011-10-24 20:00:00                  7
2011-10-24 21:00:00                  4
2011-10-24 22:00:00                  2
2011-10-25 00:00:00                  4
2011-10-25 01:00:00                  2
2011-10-25 02:00:00                  2
2011-10-25 15:00:00                  12
2011-10-25 18:00:00                  2
2011-10-25 19:00:00                  3
2011-10-25 21:00:00                  2
2011-10-25 23:00:00                  9
2011-10-26 00:00:00                  13
2011-10-26 01:00:00                  11
  • 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-07T03:20:42+00:00Added an answer on June 7, 2026 at 3:20 am

    First I entered the data with the multiple spaces replaced with tabs.

    dat$date <- as.POSIXct(dat$date, format="%Y-%m-%d %H:%M:%S")
    split(dat , as.POSIXlt(dat$date)$yday)
    # Notice these are not the same functions
    #---------------------
    $`296`
                     date obs
    1 2011-10-24 01:00:00  12
    2 2011-10-24 02:00:00   4
    3 2011-10-24 19:00:00  18
    4 2011-10-24 20:00:00   7
    5 2011-10-24 21:00:00   4
    6 2011-10-24 22:00:00   2
    
    $`297`
                      date obs
    7  2011-10-25 00:00:00   4
    8  2011-10-25 01:00:00   2
    9  2011-10-25 02:00:00   2
    10 2011-10-25 15:00:00  12
    11 2011-10-25 18:00:00   2
    12 2011-10-25 19:00:00   3
    13 2011-10-25 21:00:00   2
    14 2011-10-25 23:00:00   9
    
    $`298`
                      date obs
    15 2011-10-26 00:00:00  13
    16 2011-10-26 01:00:00  11
    

    The POSIXlt class does not work well inside dataframes but it can ve very handy for creating time based groups. It’s a list structure with these indices: ‘yday’, ‘wday’, ‘year’, ‘mon’, ‘mday’, ‘hour’, ‘min’, ‘sec’ and ‘isdt’. The cut.POSIXt function adds divisions at other natural boundaries; E.g.

    ?cut.POSIXt
      split(dat , cut(dat$date, "week") )
    

    If you wanted to sum within date:

    tapply(dat$obs, as.POSIXlt(dat$date)$yday, sum)
    #-------
    296 297 298 
     47  36  24 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fit some data to a lognormal distribution and from this generate
I'm not sure how to specifically deal with this(new to Java). Basically I have
I have some data loaded as a np.ndarray and need to convert it to
I have some arbitrary pixel data that I want to save as a PNG.
I often find this strange CDATA tag in XML files: <![CDATA[some stuff]]> I have
I have a table where I am dumping some transaction data. I have a
I'm trying to debug an issue. We have few Threads that work on data
I have an Observable and an Observer . The observable does download some stuff
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .

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.