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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:02:56+00:00 2026-05-28T00:02:56+00:00

I have two big and small dataframes (actually dataset is very very big !).

  • 0

I have two big and small dataframes (actually dataset is very very big !). The following just for working.

big  <- data.frame (SN = 1:5, names = c("A", "B", "C", "D", "E"), var = 51:55)

 SN names var
1  1     A  51
2  2     B  52
3  3     C  53
4  4     D  54
5  5     E  55

small <- data.frame (names = c("A", "C", "E"), type = c("New", "Old", "Old") )
  names type
1     A  New
2     C  Old
3     E  Old

Now I need to create and new variable in “big” with the help of “type” variable in small. The names in small and big will match and corresponding type will be stored in column type. If there is no match between the names columns it will be result in new value “unknown”. The expected output is as follows:

resultdf <- data.frame(SN = 1:5, names = c("A", "B", "C", "D", "E"), var = 51:55, 
              type = c("New","Unknown", "Old", "Unknown", "Old"))

resultdf 
  SN names var    type
1  1     A  51     New
2  2     B  52 Unknown
3  3     C  53     Old
4  4     D  54 Unknown
5  5     E  55     Old

I know this is simple question for experts but I could not figure it out.

  • 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-28T00:02:57+00:00Added an answer on May 28, 2026 at 12:02 am

    First use merge() with the argument all=TRUE to merge the two data.frames, keeping rows of big that found no matching value in the small$names. Then, replace those elements of big$type that didn’t find a match (marked by merge() with “NA”s) with the string “Unknown”.

    Note that because big and small share just one column name in common, that column is by default used to perform the merge. For more control over which columns are used as the basis of the merge, see the function’s by, by.x, and by.y arguments.

    small <- data.frame (names = c("A", "C", "E"), 
                         type = c("New", "Old", "Old"), stringsAsFactors=FALSE)
    big  <- data.frame (SN = 1:5, names = c("A", "B", "C", "D", "E"), var = 51:55,
                        stringsAsFactors=FALSE)
    
    big <- merge(big, small, all=TRUE)
    big$type[is.na(big$type)] <- "Unknown"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables big (id, bigs_name, smallid), small(id, smallguys_name) therefore two models -
I want make changes in big data.frame column names (names(mp)) with the help of
I have two divs: <div id=small></div> <div id=big></div> The small really smaller and is
I have two movie-clips, one is small-box and another is big-box .Both are rectangular
I have SQL Server 2008 Ent and OLTP database with two big tables. How
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have a small webshop-like web application, and i have big plans :-) I
i have two bitmaps in code (.NET). I'd like to search for the small
Have two folders with approx. 150 java property files. In a shell script, how
I have two applications written in Java that communicate with each other using XML

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.