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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:36:50+00:00 2026-06-18T18:36:50+00:00

Say I have these two data frames: big.table <- data.frame(idx = 1:100) small.table <-

  • 0

Say I have these two data frames:

big.table <- data.frame("idx" = 1:100)

small.table <- data.frame("idx" = sample(1:100, 10), "color" = sample(colors(),10))

I want to merge them together like this:

merge(small.table, big.table, by = "idx", all.y=TRUE)

idx           color
1     1            <NA>
2     2            <NA>
3     3         salmon2
4     4            <NA>
5     5            <NA>
6     6            <NA>
...
20   20            <NA>
21   21            <NA>
22   22           blue4
23   23          grey99
24   24            <NA>
25   25            <NA>
26   26            <NA>
...

Now I need to fill the values in the ‘color’ column down the table so that all the NAs are set to values that come before in the table.

NOTES:
The problem involves a log file generated from a computer program, not in any standard log format. Blocks of lines in this log file belong to a ‘process’ that is identified in the first line of the block. I’ve pulled out information in the relevant lines of the log file, most of which belong to a process, and created a data table containing that information (the line number, time stamp, etc.). Now I need to fill into this table the ‘process’ names that correspond to each line from a small.table which has a line number.

There might not be a ‘process’ (color in the example above) for the lines at the top of the big.table. Those lines should remain NA.

Once the first ‘process’ starts, every line between that process start line and the next belongs to the first process. When the second process starts, every line between that process start line and the next process start line belongs to the second process. And so on. The process lines are never the same line number as the other lines that I’ve collected into my log file data frame.

My plan is to create the big.table to be a sequence of all log line numbers and merge the small table to it. Then I can “fill down” the process name and merge the big table to the log file keeping only the log file with everything joined to it.

I’m open to other approaches.

  • 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-18T18:36:51+00:00Added an answer on June 18, 2026 at 6:36 pm

    It sounds like you need na.locf from the package zoo (stands for last observation carried forward):

    library(zoo)
    tbl <- merge(small.table, big.table, by = "idx", all.y=TRUE)
    tbl$color2 <- na.locf(tbl$color,na.rm = FALSE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a database called Poll and have these two table structures. poll
I have two tables: entreprises(id, name) entreprises_struct(id,entreprise_id, entreprise_child_id) let's say i have these data:
Say I have a data frame with two factors in there and I want
Let's say I have these two variables $number = 1; $word = one; and
Let's say we have these two classes: public class Base { public static int
Let's say I have these two arrays: string[] arr1 = new string[2]{Hello, Stack} string[]
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
Say I have two classes: Supplier, and Account. These classes are connected via has_one
Let's say I have these two tables: ParentDataItem ParentDataItemID ...some other fields... ChildDataItem ChildDataItemID
Let's say I have the following dataset bodysize=rnorm(20,30,2) bodysize=sort(bodysize) survive=c(0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,1,0,1,1,1) dat=as.data.frame(cbind(bodysize,survive)) I'm aware that

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.