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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:53:27+00:00 2026-06-13T08:53:27+00:00

While duplicated row (and column) names are allowed in a matrix , they are

  • 0

While duplicated row (and column) names are allowed in a matrix, they are not allowed in a data.frame. Trying to rbind() some data frames having row names in common highlights this problem. Consider two data frames below:

foo = data.frame(a=1:3, b=5:7)
rownames(foo)=c("w","x","y")
bar = data.frame(a=c(2,4), b=c(6,8))
rownames(bar)=c("x","z")
# foo               bar
#   a b               a b
# w 1 5             x 2 6
# x 2 6             y 4 8
# y 3 7

Now trying to rbind() them (Pay attention to the row names):

rbind(foo, bar)
#    a b
# w  1 5
# x  2 6
# y  3 7
# x1 2 6
# z  4 8

But for the case of matrix:

rbind(as.matrix(foo), as.matrix(bar))
#   a b
# w 1 5
# x 2 6
# y 3 7
# x 2 6
# z 4 8

Here is the problem: How to rbind() two data frames, having duplicated rows (with the same row name) removed?

  • 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-13T08:53:29+00:00Added an answer on June 13, 2026 at 8:53 am

    How about

    duprows <- which(!is.na(match(rownames(bar),rownames(foo))))
    rbind(foo,bar[-duprows,])
    

    ?

    Or (based on comments below)

    duprows <- rownames(bar) %in% rownames(foo)
    rbind(foo, bar[!duprows,])
    

    Several variations are possible depending on (1) selected matched or unmatched; (2) finding numeric or logical values for the matches.

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

Sidebar

Related Questions

Possible Duplicate: Why avoid while loops? I am trying to learn Python by following
Possible Duplicate: Erasing from a std::vector while doing a for each? I'm trying to
I have been looking for a while now but I can not find an
I'm adding values to a c# generic list while trying to prevent duplicates, but
I have a unique key set for a mysql database row so not to
I need to copy a row based on some condition(where clause), from a table,make
Possible Duplicate: nullPointerException in multi column list I have following app which fetches data
I am working on time series data, for which the key column is a
I'm trying to generate two random numbers, one for a row and one for
Possible Duplicate: Issue while saving image using savefiledialog I use windows forms in C#.

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.