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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:47:47+00:00 2026-05-24T23:47:47+00:00

I am given two very large data sets and I’ve been trying to build

  • 0

I am given two very large data sets and I’ve been trying to build a function that would find certain coordinates from one set that respect an if clause regarding the other data set. My problem is that the function I wrote is very slow and although I’ve been reading answers to questions similar in some way, I haven’t managed to make it work.
So if I am given:

>head(CTSS)    
    V1     V2     V3
1 chr1 564563 564598 
2 chr1 564620 564649
3 chr1 565369 565404
4 chr1 565463 565541
5 chr1 565653 565697
6 chr1 565861 565922

and

> head(href)
   chr      region    start      end strand nu   gene_id transcript_id
1 chr1 start_codon 67000042 67000044      +  . NM_032291     NM_032291
2 chr1         CDS 67000042 67000051      +  0 NM_032291     NM_032291
3 chr1        exon 66999825 67000051      +  . NM_032291     NM_032291
4 chr1         CDS 67091530 67091593      +  2 NM_032291     NM_032291
5 chr1        exon 67091530 67091593      +  . NM_032291     NM_032291
6 chr1         CDS 67098753 67098777      +  1 NM_032291     NM_032291

For each value in the start column from the href data set I want to find the first two values in the 3rd column of the CTSS data set smaller or equal than it and keep it in a new dataframe.
The loop I wrote:

y <- CTSS[order(-CTSS$V3), ]     
find_CTSS <- function(x, y) {
    n <- length(x$start)
    foo <- data.frame(matrix(0, n, 6))
    for (i in 1:n)
    {
        a <- which(y$V3 <= x$start[i])
        foo[i, ] = c(x$start[i], x$stop[i], y$V2[a[1]], y$V3[a[1]] , y$V2[a[2]], y$V3[a[2]])
    }

print(foo)

}
  • 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-24T23:47:47+00:00Added an answer on May 24, 2026 at 11:47 pm

    You provide little data (but see here) so it’s a bit hard to benchmark your solution. See if the below solution is meeting your needs.

    #make some fake data
    href <- data.frame(start = runif(10), stop = runif(10), other_col = sample(letters, 10))
    CTSS <- data.frame(col1 = runif(100), col2 = runif(100))
    
    # for each row in href (but extract only stop and start columns)
    result <- apply(X = href[, c("start", "stop")], MARGIN = 1, FUN = function(x, ctss) {
                criterion <- x["start"] #make a criterion
                #see which values are smaller or equal to this criterion (and sort them)
                extracted <- sort(ctss[ctss$col2 <= criterion, "col2"])
                #extract last and one to last value
                get.values <- extracted[c(length(extracted) - 1, length(extracted))] 
                #put values in data frame
                out <- as.data.frame(matrix(get.values, ncol = 2)) 
                return(out)
            }, ctss = CTSS)
    
    #pancake a list into a data.frame
    result <- do.call("rbind", result) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a design pattern that handles large data sets over the
Given the following two code options, is there any performance benefit (over a very
I have to store two files A and B which are both very large
Alright. So I have a very large amount of binary data (let's say, 10GB)
Very simple problem: given two CLLocationCoordinate2Ds, how can I get the bearing (as radians)
I have some functional code that I'm trying to speed up by eliminating the
The task I have is to (somewhat efficiently) read line-by-line through a very large,
I'm looking for software represenation for a very large amount of records ( more
I've got a data source that provides a list of objects and their properties
I need to select the counts from two tables that share a common column

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.