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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:39:48+00:00 2026-06-15T04:39:48+00:00

I am trying to figure out why the rbind function is not working as

  • 0

I am trying to figure out why the rbind function is not working as intended when joining data.frames without names.
Here is my testing:

test <- data.frame(
            id=rep(c("a","b"),each=3),
            time=rep(1:3,2),
            black=1:6,
            white=1:6,
            stringsAsFactors=FALSE
            )

# take some subsets with different names
pt1 <- test[,c(1,2,3)]
pt2 <- test[,c(1,2,4)]

# method 1 - rename to same names - works
names(pt2) <- names(pt1)
rbind(pt1,pt2)

# method 2 - works - even with duplicate names
names(pt1) <- letters[c(1,1,1)]
names(pt2) <- letters[c(1,1,1)]
rbind(pt1,pt2)

# method 3 - works  - with a vector of NA's as names
names(pt1) <- rep(NA,ncol(pt1))
names(pt2) <- rep(NA,ncol(pt2))
rbind(pt1,pt2)

# method 4 - but... does not work without names at all?
pt1 <- unname(pt1)
pt2 <- unname(pt2)
rbind(pt1,pt2)

This seems a bit odd to me. Am I missing a good reason why this shouldn’t work out of the box?

edit for additional info

Using @JoshO’Brien’s suggestion to debug, I can identify the error as occurring during this if statement part of the rbind.data.frame function

if (is.null(pi) || is.na(jj <- pi[[j]]))

(online version of code here: http://svn.r-project.org/R/trunk/src/library/base/R/dataframe.R starting at: “### Here are the methods for rbind and cbind.“)

From stepping through the program, the value of pi does not appear to have been set at this point, hence the program tries to index the built-in constant pi like pi[[3]] and errors out.

From what I can figure, the internal pi object doesn’t appear to be set due to this earlier line where clabs has been initialized as NULL:

if (is.null(clabs)) clabs <- names(xi) else { #pi gets set here

I am in a tangle trying to figure this out, but will update as it comes together.

  • 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-15T04:39:48+00:00Added an answer on June 15, 2026 at 4:39 am

    Because unname() & explicitly assigning NA as column headers are not identical actions. When the column names are all NA, then an rbind() is possible. Since rbind() takes the names/colnames of the data frame, the results do not match & hence rbind() fails.

    Here is some code to help see what I mean:

    > c1 <- c(1,2,3)
    > c2 <- c('A','B','C')
    > df1 <- data.frame(c1,c2)
    > df1
      c1 c2
    1  1  A
    2  2  B
    3  3  C
    > df2 <- data.frame(c1,c2) # df1 & df2 are identical
    >
    > #Let's perform unname on one data frame &
    > #replacement with NA on the other
    >
    > unname(df1)
      NA NA
    1  1  A
    2  2  B
    3  3  C
    > tem1 <- names(unname(df1))
    > tem1
    NULL
    >
    > #Please note above that the column headers though showing as NA are null
    >
    > names(df2) <- rep(NA,ncol(df2))
    > df2
      NA NA
    1  1  A
    2  2  B
    3  3  C
    > tem2 <- names(df2)
    > tem2
    [1] NA NA
    > 
    > #Though unname(df1) & df2 look identical, they aren't
    > #Also note difference in tem1 & tem2
    >
    > identical(unname(df1),df2)
    [1] FALSE
    > 
    

    I hope this helps. The names show up as NA each, but the two operations are different.

    Hence, two data frames with their column headers replaced to NA can be “rbound” but two data frames without any column headers (achieved using unname()) cannot.

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

Sidebar

Related Questions

Trying to figure out how to type (via events not set the value) on
Trying to figure out a way where I can pass some data/fields from a
Trying to figure out a way to throw out attributes in this data that
Trying to figure out a stack corruption error in a function when I noticed
Trying to figure out the best way to do this (And without crossing any
Trying to figure out why c++ function call returning an int crashes the whole
Trying to figure out why my code isn't working. Basically I have an elseif
Trying to figure out this MKPolygon working. I've created a whole heap MKMapPoints and
Trying to figure out why I could not set up Heroku Gem and following
Trying to figure out how to exploit the CSharpCodeProvider to compile string data at

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.