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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:57:24+00:00 2026-05-23T22:57:24+00:00

I have a whole bunch of data.frames with irregular time spacing. I would like

  • 0

I have a whole bunch of data.frames with irregular time spacing.

I would like to make a new data.frame and join the others to it, for each data.frame being joined picking the latest value out of the new data.frame.

For example, listOfDataFrames below contains a list of data.frames each of which has a time column in seconds. I find the total range, mod the range by 60 and seqn it by to obtain an increasing seqn of full minutes. Now I need to merge the list of data.frames to the left of this new seqn. e.g. if the value in mypoints is 60, the value joined to it should be the latest value <= 60.

xrange <- range(lapply(listOfDataFrames,function(x) range(x$Time)))
mypoints <- 60*do.call(seq,as.list(xrange%/%60))

I believe this is sometimes called an asof join.

Is there a simple procedure to do this?

Thanks

EDIT: this is what I currently use

xrange <- range(lapply(listOfDataFrames,function(x) range(x$Time)))
mypoints <- 60*seq(xrange[1]%/%60,1+xrange[2]%/%60)
result <- data.frame(Time=mypoints)
for(index in 1:length(listOfDataFrames))
{
  x<-listOfDataFrames[[index]]
  indices <- which(sort(c(mypoints,x$Time)) %in% mypoints) - 1:length(mypoints)
  indices[indices==0] <- NA
  newdf<-data.frame(new=x$Result[indices])
  colnames(newdf)<-paste("S",index,sep="")
  result <- cbind(result,newdf)
}

EDIT: full example

AsOfJoin <- function (listOfDataFrames) {
  xrange <- range(lapply(listOfDataFrames,function(x) range(x$Time)))
  mypoints <- 60*seq(xrange[1]%/%60,1+xrange[2]%/%60)
  result <- data.frame(Time=mypoints)
  for(index in 1:length(listOfDataFrames))
  {
    x<-listOfDataFrames[[index]]
    indices <- which(sort(c(mypoints,x$Time)) %in% mypoints) - 1:length(mypoints)
    indices[indices==0] <- NA
    newdf<-data.frame(new=x$Result[indices])
    colnames(newdf)<-paste("S",index,sep="")
    result <- cbind(result,newdf)
  }
  result[is.na(result)]<-0
  result
}


a<-data.frame(Time=c(28947.5,28949.6,29000),Result=c(10,15,9))
b<-data.frame(Time=c(28947.8,28949.5),Result=c(14,19))
listOfDataFrames <- list(a,b)
result<-AsOfJoin(listOfDataFrames)

    > a
         Time Result
    1 28947.5     10
    2 28949.6     15
    3 29000.0      9
    > b
         Time Result
    1 28947.8     14
    2 28949.5     19
    > result
       Time S1 S2
    1 28920  0  0
    2 28980 15 19
    3 29040  9 19
  • 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-23T22:57:25+00:00Added an answer on May 23, 2026 at 10:57 pm

    See my edit for answer. Apparently the best way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data warehouse containing typical star schemas, and a whole bunch of
We have a whole bunch of DLLs that give us access to our database
I have a whole bunch of files with filenames using our lovely Swedish letters
We have a whole bunch of queries that search for clients, customers, etc. You
I have a git directory which contains the a whole bunch of files and
I have the whole MVC-Model set up and use HTML views as templates. But
I have a whole heap of legacy code that I checked into my SVN
We currently have a whole suite of report designs that cover various parts of
I have checked the whole site and googled on the net but was unable
So I've never worked with stored procedures and have not a whole lot of

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.