0

I am having issues merging several data frames together. I have (plyr) uploaded and am attempting to use rbind to merge 6 data frames together. The output keeps telling me it is the wrong names. I do have each of the objects named as data.frames. Could that be the issue?

    #Merging Species
    Full.species <- rbind(Papio,Cebus,Gorilla,Human,Macaca,Pantrog, 
    use.names=TRUE)

Here is my output error message:

    Error in match.names(clabs, names(xi)) : 
    names do not match previous names
1
  • 1
    This is off-topic for CV, but a minimally reproducible example may be ontopic for stack-overflow. Your best bet is to verify that the column names of the objects are indeed the same. See ?colnames. Commented Feb 9, 2018 at 17:55

2 Answers 2

1

There are several situations and it is not clear which of those is yours but:

1) rbind will work if the data frames have the same names. Given your error message I assume that that is not your case.

2) If the data frames have the same number of columns and the first column of each corresponds and the second column of each corresponds, etc. then just change the column names on all the data frames but one to the names on that data frame.

names(DF3) <- names(DF2) <- names(DF)
rbind(DF, DF2, DF3)

3) If the different names should be put in different columns then use rbind.fill from plyr:

library(plyr)

rbind.fill(DF, DF2, DF3)
Sign up to request clarification or add additional context in comments.

Comments

0

Personally, I like the data.table package for this task:

library(data.table)
Full.species <- rbindlist(list(Papio,Cebus,Gorilla,Human,Macaca,Pantrog), fill=TRUE)

fill=TRUE will fill any columns missing from a given dataset with NAs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.