This article describes how to merge two data files together as a single R data set.
- A professional user license.
- Displayr Cloud Drive enabled on your account - contact email@example.com to enquire about access to this feature.
- A Displayr document with two loaded data sets in your Data Sets tree that have the same structure and column names for the data to merge but different records.
- A raw data table for each data set as per the steps outlined in How to Create a Raw Data Table From Variable(s).
Step 1: Export data sets to the Cloud Drive
1. In the toolbar go to Calculation > Custom Code.
2. Use the below R code to save both files to the Cloud Drive as ".rds" files:
In this example, my raw data tables are called wave1 and wave2, with the saved rds files exported as data.wave1.rds and data.wave1.rds respectively.
Step 2: Import and merge data sets from the Cloud Drive
1. Go to Data Sets > Plus (+) > R.
2. Enter a name for the data set under Name.
3. Update and input the below R code where it states "Enter your R code here":
w1 = QLoadData("data.wave1.rds")
w2 = QLoadData("data.wave2.rds")
merged = merge(w1,w2,all=TRUE)
This code loads both previously exported data sets and then merges them together using the merge function. Note, you must have the exact same format and column name when merging cases into the same column of data. By using the all=TRUE argument, it ensures the merge will also add any additional columns of data between the files.
4. R doesn’t have the same level of metadata as some file types, like SSS and SAV. For example, variables in an R data frame do not have the concept of both Name and Label. Remember to add such information after you have added your data set.