Tables - Merge Two Tables

From Q
Jump to: navigation, search

Options

The options that are available for this analysis are:

  • 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.

How to run this analysis

This feature uses pre-scripted R.

  1. Select this analysis from the Create menu.
  2. An R object appears in the Report for which you specify/customize the Options over in the Object Inspector on the right.
  3. Click Calculate (or set to 'Automatic' so that the output automatically updates if you make any changes to the source data or options).

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))