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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:07:06+00:00 2026-05-27T17:07:06+00:00

I have the following problem. I have a data set that has the beginning

  • 0

I have the following problem. I have a data set that has the beginning (STRTTIME) and ending time (ENDTIME) of a trip in military time format. I want to figure out the number of trips in each 15 minute time increment. My goal is to determine the number of trips that take place in each 15 minute time period starting from 0000 to 2359 (96 time slices). I can write 96 dummy variables in excel and do it but I would rather have some code in either R or Python (I am learning both so my knowledge is rudimentary). I can put a counter and then increment but I am not sure how to deal with two time variables and find myself hitting a deadend. My example is below. Here is some sample data (in CSV format).

  1. Suppose a trip starts at 0805 and ends at 0840 then each 15 minute period will have following values:
    • 0000-0015 – 0
    • 0015-0030 – 0
    • ….
    • 0800-0815 – 2/3
    • 0815-0830 – 1
    • 0830-0845 – 2/3
    • 0845-0900 – 0
    • …
    • 2330-2345 – 0
    • 2345-2400 – 0
  2. Suppose another trip starts at 0810 and ends at 0850 then each 15 minute period will have the following values:
    • 0000-0015 – 0
    • 0015-0030 – 0
    • ….
    • 0800-0815 – 1/3
    • 0815-0830 – 1
    • 0830-0845 – 1
    • 0845-0900 – 1/3
    • …
    • 2330-2345 – 0
    • 2345-2400 – 0
  3. After processing these 2 records the values in the 15 minute period dummy fields will be as follows (i.e. it has incremented it by the value of the field in the previous record):
    • 0000-0015 – 0
    • 0015-0030 – 0
    • ….
    • 0800-0815 – 1
    • 0815-0830 – 2
    • 0830-0845 – 5/3
    • 0845-0900 – 1/3
    • …
    • 2330-2345 – 0
    • 2345-2400 – 0

Any code to do this is much 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-27T17:07:06+00:00Added an answer on May 27, 2026 at 5:07 pm

    As there is no answer in R yet, I will add one for that. I feel the solution might be a bit more elegant than python, but that is a matter of taste.

    First, we will have to read the data:

    data <- read.csv('sample_data.csv')
    

    Then, I would like to convert the times to decimal format. Therefore, I do use the hour and min provided and not the military format. That would not be a problem, though, as you could always convert the values using simple integer arithmetic.

    data <- cbind(data, start = data$STARTHR + data$STARTMIN/60, end= data$ENDHR + data$ENDMIN/60)
    

    Now generate the time intervals (which we will identify by their starttime)

    intervals <- seq(0, 23.75, by=0.25)
    

    That part is a bit tricky…
    First we will check which trips end later than our interval end. All those trips we shall assign a 1, the trips that end before our interval we will assign a 0. If the trip ends within the interval, we will use assign the corresponding fraction between 0 and 1.

    endvalues <- (pmax(pmin(outer(data$end, intervals, FUN="-"), 0.25), 0) / 0.25)  
    

    Notice the use of outer. Here, the function “-” (subtraction) is used for all combinations of endtimes and the intervals vector. All other operations are element wise. I suggest that you just test the operation step by step, then it should be obvious what is done.

    Similarly, we will do this with the startintervals, but now we will use negative signs.

    startvalues <- (pmax(pmin(-outer(data$start, intervals, FUN="-"), 0), -0.25) / 0.25)
    

    That enables us to generate a matrix that has a 1 whenever the interval is fully contained within the trip:

    resultmatrix <- endvalues + startvalues
    

    Finally, we may sum up over all trips and receive the number of trips within each interval:

    intervalcount <- apply(resultmatrix, 2, sum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem in my Data Structures and Problem Solving using Java
I have the following casting problem when my data structure sSpecificData contains a field
I have the following problem: list.c struct nmlist_element_s { void *data; struct nmlist_element_s *next;
I have an extremely simple JSON object that looks like the following: var data
I have the following problem: I need to validate data in a controller, which
I am using jQuery 1.7.1. and I have the following question/problem: The code has
Say I have core data objects of type obj that has a property propertyA
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem: I have an HTML textbox ( <input type=text> )

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.