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?

4
  • 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. Commented Dec 19, 2016 at 3:15
  • 2
    Please provide a MCVE. Commented Dec 19, 2016 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). Commented Dec 19, 2016 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. Commented Dec 19, 2016 at 12:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is just great and super simple @Cris

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.