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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:14:54+00:00 2026-05-29T06:14:54+00:00

I have a long numerical time series data of approximately 200,000 rows (lets call

  • 0

I have a long numerical time series data of approximately 200,000 rows (lets call it Z).

In a loop, I subset x (about 30) consecutive rows from Z at a time and treat them as the query point q.

I want to locate within Z the y (~300) most correlated time series segments of length x (most correlated with q).

What is an efficient way to accomplish this?

  • 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-29T06:14:54+00:00Added an answer on May 29, 2026 at 6:14 am

    The code below finds the 300 segments you are looking for and runs in 8 seconds on my none too powerful Windows laptop, so it should be fast enough for your purposes.

    First, it constructs a 30-by-199971 matrix (Zmat), whose columns contain all of the length-30 “time series segments” you want to examine. A single call to cor(), operating on the vector q and the matrix Zmat, then calculates all of the desired correlation coefficients. Finally, the resultant vector is examined to identify the 300 sequences having the highest correlation coefficients.

    # Simulate data
    nZ <- 200000
    nq <- 30
    Z <- rnorm(nZ)
    q <- seq_len(nq)
    
    # From Z, construct a 30 by 199971 matrix, in which each column is a
    # "time series segment". Column 1 contains observations 1:30, column 2
    # contains observations 2:31, and so on through the end of the series.
    Zmat <- sapply(seq_len(nZ - nq + 1),  
                   FUN = function(X) Z[seq(from = X, length.out = nq)])
    
    # Calculate the correlation of q with every column/"time series segment.
    Cors <- cor(q, Zmat)
    
    # Extract the starting position of the 300 most highly correlated segments    
    ids <- order(Cors, decreasing=TRUE)[1:300]
    
    # Maybe try something like the following to confirm that you have
    # selected the most highly correlated segments.
    hist(Cors, breaks=100)
    hist(Cors[ids], col="red", add=TRUE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have long been of the opinion that the time and resources it would
I have long HTTP request ( generating large Excel file - about 60K records
I'm trying to find all data items that have long/lats that are contained by
I have numerical text data lines ranging between 1mb - 150 mb in size,
I have long since forgotten the password for the root user on one of
I have long been wondering why lazy evaluation is useful. I have yet to
I have long tables generated by datagrid control that go beyond the page width.
I have long recognized that any set of whitespace in an HTML file will
I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c//sg_ioctl()
I wish to have long and short forms of command line options invoked using

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.