Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two data frames together that have the same variable names and data types

Tags:

r

I have tried the merge function to merge two csv files that I imported. They both have the same variable names and data types but each time I run merge all that I get is an object that contains the names of the two data frames. I have tried the following:

# ex1
obj <- merge(obj1, obj2, by=obj)
# ex2
obj <- merge(obj1, obj2, all)

and several other iterations of the above.

Is merge the correct function? If so, what am I doing wrong?

like image 228
Brandon Avatar asked Jun 14 '10 19:06

Brandon


People also ask

How do I merge two data frames?

The concat() function in pandas is used to append either columns or rows from one DataFrame to another. The concat() function does all the heavy lifting of performing concatenation operations along an axis while performing optional set logic (union or intersection) of the indexes (if any) on the other axes.

Which function is used to merge two data frames?

Pandas DataFrame merge() Function Syntax This is the most important parameter to define the merge operation type. These are similar to SQL left outer join, right outer join, full outer join, and inner join. on: Column or index level names to join on. These columns must be present in both the DataFrames.

How do I merge two DataFrames with the same column names in R?

To combine two data frames with same columns in R language, call rbind() function, and pass the two data frames, as arguments. rbind() function returns the resulting data frame created from concatenating the given two data frames. For rbind() function to combine the given data frames, the column names must match.


1 Answers

I am guessing that you actually want to rbind the data.frames, rather than merging them?

Try:

obj <- rbind(obj1, obj2)

merge() is really used to do the equivalent of a JOIN in SQL.

like image 97
Shane Avatar answered Oct 18 '22 22:10

Shane