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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:31:03+00:00 2026-06-13T04:31:03+00:00

I have two dataframes, looking sort of like: Source_name <- c(name1, name2, name3, name4,

  • 0

I have two dataframes, looking sort of like:

Source_name <- c("name1", "name2", "name3", "name4", "name5")
Target_name <- c("name10", "name11", "name12", "name13", "name14")
values <- c("asd", "213", "kahsd", "a9u", "oau92")
values2 <- c("asdd", "oau892", "kahsd", "213", "213")
dat <- cbind(Source_name, values)
daf <- cbind(Target_name, values2)

dat
Source_name     values 
[1,] "name1"     "asd"  
[2,] "name2"     "213"  
[3,] "name3"     "kahsd"
[4,] "name4"     "a9u"  
[5,] "name5"     "oau92"

daf
Target_name     values2  
[1,] "name10"    "asdd"   
[2,] "name11"    "oau892"  
[3,] "name12"    "kahsd"
[4,] "name13"    "213"   
[5,] "name14"    "213"    

Each value only occurs once in dat, but may occur more than once in daf (or not at all). I would like to record those values in dat that occur at most once in daf, as per the desired_output data.frame.

unique_values <- c( "asd", "kahsd", "a9u", "oau92")
Source_name <- c( "name1", "name3", "name4", "name5")
Target_name <- c( "NA", "name12", "NA", "NA")
desired_output <- data.frame(cbind(unique_values, Source_name, Target_name))

desired_output
     unique_values    Source_name Target_name   
 1         asd         name1       
 3         kahsd       name3       name12   
 2         a9u         name4    
 4         oau92       name5   

I imagine there’s an easy way to do this using apply or something, but Im stumped.

  • 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-13T04:31:05+00:00Added an answer on June 13, 2026 at 4:31 am

    You could merge your two data.frames:

    dd <- merge(dat, daf, all.x = TRUE, by.x = "values", by.y = "values2")
    dd
    #   values Source_name Target_name
    # 1    213       name2      name13
    # 2    213       name2      name14
    # 3    a9u       name4        <NA>
    # 4    asd       name1        <NA>
    # 5  kahsd       name3      name12
    # 6  oau92       name5        <NA>
    

    Then remove rows with values that show up twice or more:

    dd[unlist(Filter(function(x)length(x)<2, split(seq_len(nrow(dd)), dd$values))), ]
    #   values Source_name Target_name
    # 3    a9u       name4        <NA>
    # 4    asd       name1        <NA>
    # 5  kahsd       name3      name12
    # 6  oau92       name5        <NA>
    

    Or as @hadley pointed out in the comments (thanks!):

    dd[ave(dd$values, dd$values, FUN = length) < 2, ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dataframes, much like these: data = data.frame(data=cbind(1:12,rep(c(1,2),6),rep(c(1,2,3),4))) colnames(data)=c('v','h','c') lookup = data.frame(data=cbind(c(rep(1,3),rep(2,3)),rep(c(1,2,3),2),21:26))
I have two dataframes and I would like to do independent 2-group t-tests on
I have two dataframes; one is 48 rows long and looks like this: name
I have two dataframes with the same number of columns. I'm writing a function
Suppose we have the contents of tables x and y in two dataframes in
I have two dataframes and I wish to insert the values of one dataframe
Before I end up at -7 like Two by two matching between dataframes in
I have two big and small dataframes (actually dataset is very very big !).
I've got two dataframes that look like this: ==fileA LmjF.01 257506 257508 1 LmjF.01
I have two data frames that look like something like the following: df1 <-

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.