Tables - Merge Two Tables

From Q
Jump to: navigation, search

Merges tables with matching row or column names. The merged table is an R Output and will not run any significance testing.

How to Merge Two Tables

  1. Add the object:
    1. In Displayr: Insert > More > Tables > Merge Two Tables
    2. In Q: Create > Tables > Merge Two Tables
  2. In Inputs > First Table specify the first table to merge.
  3. In Inputs > Second Table specify the second table to merge.
  4. Use Inputs > Join Direction to specify how the tables should be merged.

Example

The table below merges two tables, Brand Awareness and Preferred Cola using the side-by-side join direction.

A merged table of two input tables joined side-by-side

Options

The options in the Object Inspector are organized into two tabs: Inputs and Properties.

Inputs

First table and Second table: The tables to merge. Join direction: Whether to join the tables by side-by-side (must have some rows in common) or up-and-down (must have some columns in common). Handle non-matching rows/columns: The tables that you are merging might have row (or column) names that do not match. This option allows you to specify how to handle the non-matches.

Keep all: Keep all rows from both tables. Rows that do not match the other table will be blank.
Keep all from first table: Keep all the rows from the first table and any matching rows from the second. Non-matching rows in the second table will be blank.
Keep all from second table: Keep all the rows from the second table and any matching rows from the first. Non-matching rows in the first table will be blank.
Matching only: Keep only the rows that are common between the two tables.

Properties

This tab contains options for formatting the size of the object, as well as the underlying R code used to create the visualization, and the JavaScript code use to customize the Object Inspector itself (see Object Inspector for more details about these options). Additional options are available by editing the code.

More Information

See also

This function can only join two tables but has several options for handling non-matching labels. If you want to merge many tables see Tables - Merge Two or More Tables, however, you will have less control over non-matching labels.

Code

form.setHeading("Merge Two Tables")
form.dropBox({
    name: "leftinput",
    label: "First table",
    types: ["table", "RItem:matrix,array,data.frame,table"]
})
form.dropBox({
    name: "rightinput",
    label: "Second table",
    types: ["table", "RItem:matrix,array,data.frame,table"]
})
form.comboBox({
    name: "joindirinput",
    label: "Join direction",
    alternatives: ["Side-by-side", "Up-and-down"]
})
form.comboBox({
    name: "nonmatchinginput",
    label: "Non-matching rows/columns",
    alternatives: ["Keep all", "Keep all from first table", "Keep all from second table", "Matching only"],
    default_value: "Keep all",
    required: false
})
library(flipTables)

merged <- Merge2Tables(left = QInputs(leftinput), right = QInputs(rightinput), direction = QInputs(joindirinput), nonmatching = QInputs(nonmatchinginput))