Skip to content
christophergandrud edited this page Jul 27, 2012 · 6 revisions

In R you can use data from multiple objects in one statistical analysis. However, this can be very hazardous. The data needs to have the same exact order across all of the objects or else you will get misleading results. If they are not in the same order R will confuse variable values from one observation with those from another observation. It is often best practice to merge all of your data together into one data frame object using ID Variables.

On this page we'll learn how to connect different objects into one data set. The first two ways are just matrix operations that join objects together either by columns or rows. These commands are called cbind and rbind, respectively. The third command merge is a bit smarter. It combines two objects based on common ID Variables that they share.

cbind to Merge Columns

Some times you may have two objects that have different columns but the rows match perfectly. In these cases you can simply use the cbindcommand.

Need to Complete

rbind to Append Rows

If you have the same columns, but the rows are different you can use the rbind command to append one object to the bottom of another.

Need to Complete

The merge Command

Need to Complete

merge Warning

By default the merge command only merges the parts of dataframes that have complete data. It will effectively delete observations without complete data. To avoid deleting these observations include the argument all = TRUE.

Clone this wiki locally