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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:50:24+00:00 2026-06-06T09:50:24+00:00

I have 100 text files which contains time series starting and ending at different

  • 0

I have 100 text files which contains time series starting and ending at different point of times. I want to extract the values for common period of time in the series.
Use the following code to generate the sample data:

set.seed(1)
D1 = data.frame(time = seq(ISOdatetime(2012, 6, 26, 3, 15, 00), 
                       length = 500, by = 900),
            value = rnorm(500))
D2 = data.frame(time = seq(ISOdatetime(2012, 6, 24, 5, 30, 00),
                       length = 541, by = 900),
            value = rnorm(541))
D3 = data.frame(time = seq(ISOdatetime(2012, 6, 23, 5, 45, 00),
                       length = 700, by = 900),
            value = rnorm(700))

This data will give you 3 time series starting and ending and different times. I wish to keep only the values for common time period and remove the rest. i.e.
if,

  • 1st series starts with “2012-6-26 3:45:26” ends with “2012-8-07 4:45:26”
  • 2nd with “2012-6-24 5:55:27” ends with “2012-7-28 7:45:26”
  • 3rd with “2012-6-23 5:04:30” ends with “2012-7-27 4:45:26”

Then I wish to keep the data of intersection of the three time series i.e. data corresponding to:-

  • start: “2012-6-26 3:45:26”
  • end:”2012-7-27 4:45:26″
  • for all the 3 series and remove the rest.

I searched SO and other websites but didn’t find any solution. Need help on that.
How do I achieve 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-06T09:50:31+00:00Added an answer on June 6, 2026 at 9:50 am

    It seems like you need to familiarize yourself with the xts package. Convert your data frame to xts time series objects and use merge. merge will merge all values, so if you want values occurring in all, you can also use na.omit.

    require(xts)
    D1 = xts(d1$Value, d1$Time)
    D2 = xts(d2$Value, d2$Time)
    D3 = xts(d3$Value, d3$Time)
    temp = merge(D1, D2, D3)
    

    Here is some example output. For head and tail, note the presence of NA values.

    head(temp)
    #                              D1 D2 D3
    # 2012-06-26 13:15:19 -0.50219235 NA NA
    # 2012-06-26 13:30:19  0.13153117 NA NA
    # 2012-06-26 13:45:19 -0.07891709 NA NA
    # 2012-06-26 14:00:19  0.88678481 NA NA
    # 2012-06-26 14:15:19  0.11697127 NA NA
    # 2012-06-26 14:30:19  0.31863009 NA NA
    tail(temp)
    #                     D1 D2         D3
    # 2012-07-04 05:45:19 NA NA  1.4799645
    # 2012-07-04 06:00:19 NA NA -0.3942801
    # 2012-07-04 06:15:19 NA NA -0.6767234
    # 2012-07-04 06:30:19 NA NA -0.2425192
    # 2012-07-04 06:45:19 NA NA  0.4547177
    # 2012-07-04 07:00:19 NA NA  1.1712661
    head(na.omit(temp))
    #                             D1          D2          D3
    # 2012-06-27 14:15:19 -0.3329234 -1.63230970  0.75619287
    # 2012-06-27 14:30:19  1.3631137 -0.06299626 -1.36131851
    # 2012-06-27 14:45:19 -0.4691473 -0.70544686 -0.60876462
    # 2012-06-27 15:00:19  0.8428756 -0.31417818 -0.21174696
    # 2012-06-27 15:15:19 -1.4579937 -0.26694627 -0.67847242
    # 2012-06-27 15:30:19 -0.4003059  0.15315947  0.06665787
    tail(na.omit(temp))
    #                              D1         D2          D3
    # 2012-07-01 16:45:19 -0.49419020  1.1911322  2.73143169
    # 2012-07-01 17:00:19 -1.71111303  0.7613245  0.57057667
    # 2012-07-01 17:15:19  0.04005805 -0.1210687  1.32083870
    # 2012-07-01 17:30:19 -0.56114348 -1.2250590  0.09951626
    # 2012-07-01 17:45:19 -2.55736206 -0.1637461 -0.39435301
    # 2012-07-01 18:00:19 -0.69677881 -1.3138963  0.63649492
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 100 rows of text that I want to tokenize, which are
I have a static page, which contains multiple links to text files on the
Let's say I have a text file that is 100 lines long. I want
I have a Java program which uses a lot of text files. The program
I have a Text file which contains data (4 to 5 paragraph) and then
I do have a file f1 which Contains some text lets say All is
I have 100 text files in a directory. The format of the filename is
Hi I have a text file which contains some numerical data. Of that text
I have a directory in which I have 1000 txt.files in it. I want
I have a hundred text files to which I would like to insert the

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.