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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:13+00:00 2026-05-28T14:00:13+00:00

Let’s say I have two data frames. Each has a DAY, a MONTH, and

  • 0

Let’s say I have two data frames. Each has a DAY, a MONTH, and a YEAR column along with one other variable, C and P, respectively. I want to merge the two data frames in two different ways. First, I merge by data:

test<-merge(data1,data2,by.x=c("DAY","MONTH","YEAR"),by.y=c("DAY","MONTH","YEAR"),all.x=T,all.y=F)

This works perfectly. The second merge is the one I’m having trouble with. So, I currently I have merged the value for January 5, 1996 from data1 and the value for January 5, 1996 from data2 into one data frame, but now I would like to merge a third value onto each row of the new data frame. Specifically, I want to merge the value for Jan 4, 1996 from data2 with the two values from January 5, 1996. Any tips on getting merge to be flexible in this way?

sample data:

data1
C DAY MONTH YEAR
1   1     1 1996
6   5     1 1996
5   8     1 1996
3  11     1 1996
9  13     1 1996
2  14     1 1996
3  15     1 1996
4  17     1 1996    

data2
P DAY MONTH YEAR
1   1     1 1996
4   2     1 1996
8   3     1 1996
2   4     1 1996
5   5     1 1996
2   6     1 1996
7   7     1 1996
4   8     1 1996
6   9     1 1996
1  10     1 1996
7  11     1 1996
3  12     1 1996
2  13     1 1996
2  14     1 1996
5  15     1 1996
9  16     1 1996
1  17     1 1996
  • 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-28T14:00:14+00:00Added an answer on May 28, 2026 at 2:00 pm

    Make a new column that is a Date type, not just some day,month,year integers. You can use as.Date() to do this, though you will need to look up the right format the format= argument given your string. Let’s call that column D1. Now do data1$D2 = data1$D1 + 1. The key point here is that Date types allow simple date arithmetic. Now just merge by x=D1 and y=D2.

    In case that was confusing, the bottom line is that you need to covert you columns to Date types so that you can do date arithmetic.

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

Sidebar

Related Questions

Let's say I have a large set of data within which each datum has
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I have an Access database table that has 2 columns: one is
Let's say I'm building a data access layer for an application. Typically I have
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I have a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have table with column 'URL' whrere I store urls like this
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's say you create a wizard in an HTML form. One button goes back,
Let's say you have a class called Customer, which contains the following fields: UserName

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.