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

  • Home
  • SEARCH
  • 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 8250777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:00:50+00:00 2026-06-08T00:00:50+00:00

I’m trying to backfill a fully outerjoined table with nearest preceding column data. The

  • 0

I’m trying to backfill a fully outerjoined table with nearest preceding column data.

The data frame I have looks like..
(No rows have both sides as NA and the table is sorted by date).

              date     X         Y
2012-07-05 00:01:19   0.0122     NA
2012-07-05 03:19:34   0.0121     NA
2012-07-05 03:19:56   0.0121   0.027
2012-07-05 03:20:31   0.0121     NA
2012-07-05 04:19:56   0.0121   0.028
2012-07-05 04:20:31   0.0121     NA
2012-07-05 04:20:50   0.0121     NA
2012-07-05 04:22:29   0.0121   0.027
2012-07-05 04:24:37   0.0121     NA
2012-07-05 20:48:45   0.0121     NA
2012-07-05 23:02:34    NA      0.029
2012-07-05 23:30:45    NA      0.029

with this, I’m looking to..

  1. leave the non-data missing rows as it is.
  2. If either one side is missing (NA), then fill it with the “nearest preceding” row which has valid opposite side’s value.

And so as the result, I would like to have the table looking like…

              date     X         Y
2012-07-05 00:01:19   0.0122     NA
2012-07-05 03:19:34   0.0121     NA
2012-07-05 03:19:56   0.0121   0.027
2012-07-05 03:20:31   0.0121   0.027
2012-07-05 04:19:56   0.0121   0.028
2012-07-05 04:20:31   0.0121   0.028
2012-07-05 04:20:50   0.0121   0.028
2012-07-05 04:22:29   0.0121   0.027
2012-07-05 04:24:37   0.0121   0.027
2012-07-05 20:48:45   0.0121   0.027
2012-07-05 23:02:34   0.0121   0.029
2012-07-05 23:30:45   0.0121   0.029

What kind of R commands can I use to achieve 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-06-08T00:00:52+00:00Added an answer on June 8, 2026 at 12:00 am

    Use na.locf from the zoo package

    dat <- read.table(text="2012-07-05 00:01:19   0.0122     NA
    2012-07-05 03:19:34   0.0121     NA
    2012-07-05 03:19:56   0.0121   0.027
    2012-07-05 03:20:31   0.0121     NA
    2012-07-05 04:19:56   0.0121   0.028
    2012-07-05 04:20:31   0.0121     NA
    2012-07-05 04:20:50   0.0121     NA
    2012-07-05 04:22:29   0.0121   0.027
    2012-07-05 04:24:37   0.0121     NA
    2012-07-05 20:48:45   0.0121     NA
    2012-07-05 23:02:34    NA      0.029
    2012-07-05 23:30:45    NA      0.029")
    
    require("zoo")
    na.locf(dat)
    #           V1       V2     V3    V4
    #1  2012-07-05 00:01:19 0.0122  <NA>
    #2  2012-07-05 03:19:34 0.0121  <NA>
    #3  2012-07-05 03:19:56 0.0121 0.027
    #4  2012-07-05 03:20:31 0.0121 0.027
    #5  2012-07-05 04:19:56 0.0121 0.028
    #6  2012-07-05 04:20:31 0.0121 0.028
    #7  2012-07-05 04:20:50 0.0121 0.028
    #8  2012-07-05 04:22:29 0.0121 0.027
    #9  2012-07-05 04:24:37 0.0121 0.027
    #10 2012-07-05 20:48:45 0.0121 0.027
    #11 2012-07-05 23:02:34 0.0121 0.029
    #12 2012-07-05 23:30:45 0.0121 0.029
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.