TableJoin
Requires Analytica 5.1 or later.
This function is currently experimental and not exposed. It could be subject to change in a future release.
Computes the join of two relational tables, «x1» and «x2».
The result is indexed by two local indexes, Pair
and Row
. The result index Row
ranges from 1 to the number of rows in the joined table. Let result denote the result, then result[.Pair=1]
is a map from Result.Row
to «row1», and result[.Pair=2]
is a map from Result.Row
to «row2».
Parameters
- «x1»: The first relational table, indexed by «row1» and «col1».
- «x2»: The second relation table, indexed by «row2» and «col2».
- «sharedCol»: (Optional) A list of the columns appearing in both «col1» and «col2» that are to be matched during the join. A shared column must have the same label in «col1» and «col2», and it is the label or labels from «col1» and «col2» that are passed in this parameter. When this parameter is not specified, all columns that have the same labels in the «col1» and «col2» indexes, ignoring the final column in each, is used. If you specify
[]
for this parameter, a cross-join is performed. - «joinType»: (Optional) Can be
'Inner'
,'Outer'
,'Left'
or'Right'
. Specifies the join type. - «position»: (Optional) When true, the result contains the positions in «row1» and «row2». When false, contains the labels from «row1» and «row2».
Examples
TBD
Related ways of doing joins
In general, there are alternative ways in Analytica for computing joins when a single column is shared. When multiple columns are shared, then TableJoin is really the only easy way to do it.
Left joins with a single key (column) occur frequently in practice, but are usually done the Slice or Subscript operator. For example, suppose Zip_of_person
is indexed by Person
and contains the zip code of each person, and County_by_zip
is indexed by Zip
. Then County_by_zip[Zip=Zip_of_person]]
returns the county for each person, which is logically a left join, but a far simpler and more natural method.
Enable comment auto-refresher