0

This is the first dataframe E I have

My goal is stack these similiar data frames as one, but I don't care the different column names they have.

First, my code is:

D <- rbind(E, N1, N2)

But it has the error:

Error in match.names(clabs, names(xi)) : names do not match previous names

Then I realized this happended because of the column names of each dataframe re not matching. So I tried the codes:

names(xd.small[[1]]) <- names(xd.small[[2]]) 
identical(names(xd.small[[1]]), names(xd.small[[2]]) )
[1] TRUE

After that, it still had the same error:

Error in match.names(clabs, names(xi)) : names do not match previous names

I just want to stack these three data frames together, and I don't care they don't share same column names. Is it possible?

Uwe
  • 41,420
  • 11
  • 90
  • 134
  • 3
    Share the data please. `dput(E)` . You can actually rbind dataframes with non-matching column names, so I think it might be a problem with your data. – Jean Dec 19 '16 at 03:15
  • 2
    Please provide a [MCVE](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). – Christoph Dec 19 '16 at 10:49
  • 2
    Please, [edit] your question and povide sample data of all three data.frames `E`, `N1`, and `N2` using `dput()`. At least show the result of `str(E)`, `str(N1)`, and `str(N2)`. – Uwe Dec 19 '16 at 12:38
  • This problem may be due to different levels in either column. What is the format of your data str(E). If one of your variable has been transformed into factor, change it into a numerical or character variable before cbind-ing. – Ervan Dec 19 '16 at 12:40

1 Answers1

4

Simply use:

colnames(E)=colnames(N1)=colnames(N2)

D <- rbind(E, N1, N2)

Remember that for the rbind to work the dataframes should have the same number of columns.

Cris
  • 787
  • 1
  • 5
  • 19