join
combine two tables or timeseries
Syntax
[t, [idx]] = join(tleft, tright) [t, [idx]] = join(tleft, tright, , OptionName, Value, ...)
Arguments
- tleft
Left table or timeseries object.
- tright
Right table or timeseries object.
- t
table or timeseries object.
- idx
column vector of doubles: indices of rows in tright.
- "Keys", vector of strings or doubles
key variables must be present in tleft and tright. "Keys" cannot be used at the same time as "LeftKeys" and "RightKeys".
- "LeftKeys", vector of strings or doubles
key variables must be present in tleft. It must be used with "RightKeys".
- "RightKeys", vector of strings or doubles
key variables must be present in tright. It must be used with "LeftKeys".
- "LeftVariables", vector of strings or doubles
variables of tleft that will be included in t. By default, all variables of tleft are included in t.
- "RightVariables", vector of strings or doubles
variables of tright that will be included in t. By default, all variables of tright except the key variable are included in t.
- "KeepOneCopy", vector of strings
only variables of tleft will be included in t. By default, common variables to tleft and tright are added to t with a suffix *_Tleft for tleft and *_Tright for tright.
Optional pairs OptionName, Value are:
Description
t = join(tleft, tright)
combines the tables or timeseries tleft and tright if they have at least one common variable name (key variable) and
that the values of the key variable(s) of tleft must match those of tright. The values of the key variable(s) of tright must be unique and must contain all values
in the key variable(s) of tleft. The output t will be of the same type as tleft and will have also the same number of rows.
t = join(tleft, tright, "Keys", keys)
allows to specify the key variables used to combine tleft and tright.
t = join(tleft, tright, "LeftKeys", leftkeys, "RightKeys", rightkeys)
is useful if data to merge is not contained in the same variable name(s)
or at the same position(s) in tleft and tright. "LeftKeys" and "RightKeys" both must specify the same number of key variables.
The "Keys" keyword should not be used with "LeftKeys" and "RightKeys".
t = join(..., "LeftVariables", leftvars)
merges data from tleft and tright an includes only the variables contained in leftvars in the output t.
Same behavior for "RightVariables". It is not possible to include row names or row times from tleft or tright.
t = join(..., "KeepOneCopy", value)
allows to keep only the variables of tleft if theses variables are common to tleft and tright and not used as key variables.
[t, idx] = join(...)
returns a column vector of indices of tright verifying t(1,...) = tright(idx(1),...), t(2, ...) = tright(idx(2), ...), t($, ...) = tright(idx($), ...).
Examples
Join tleft and tright
tleft = table([1; 2; 3], ["a"; "b"; "c"], "VariableNames", ["a", "b"]); tright = table([3; 1; 2; 3], ["c"; "a"; "b"; "d"], [10; 12; 14; 0], "VariableNames", ["a", "b", "c"]); t = join(tleft, tright)
Join tleft and tright with Keys
tleft = table([1; 2; 3], ["a"; "b"; "c"]); tright = table([3; 1; 2; 3], ["c"; "a"; "b"; "d"]); t = join(tleft, tright, "Keys", "Var2")
Join tleft and tright with LeftKeys and RighKeys
tleft = table([1; 2; 3], ["a"; "b"; "c"], "VariableNames", ["a", "b"]); tright = table([3; 1; 2; 4], ["c"; "a"; "b"; "d"], [10; 12; 14; 0], "VariableNames", ["a", "d", "c"]); [t, idx] = join(tleft, tright, "LeftKeys", "b", "RightKeys", "d") tright(idx)
With "KeepOneCopy"
tleft = table([1; 2; 3], ["a"; "b"; "c"], "VariableNames", ["a", "b"]); tright = table([3; 1; 2; 3], ["c"; "a"; "b"; "d"], [10; 12; 14; 0],"VariableNames", ["a", "b", "c"]); t = join(tleft, tright, "Keys", "b") t = join(tleft, tright, "Keys", "b", "KeepOneCopy", "a")
With timeseries
tleft = timeseries(hours(1:3)', ["a", "b", "c"]', "VariableNames", ["hours", "b"]); tright = timeseries(hours([3;1;2;4]), ["c"; "a"; "b";"d"], [10; 12; 14; 0], "VariableNames", ["hours", "d", "c"]); t = join(tleft, tright) t = join(tleft, tright, "LeftKeys", "b", "RightKeys", "d")
With timeseries and table
tleft = timeseries(hours(1:3)', ["a", "b", "c"]', "VariableNames", ["hours", "b"]); tright = table([3; 1; 2; 3], ["c"; "a"; "b"; "d"], [10; 12; 14; 0],"VariableNames", ["a", "b", "c"]);; t = join(tleft, tright)
See also
- table — create a table from variables
- timeseries — create a timeseries - table with time as index
History
Version | Description |
2025.1.0 | Introduction in Scilab. |
Report an issue | ||
<< isregular | Timeseries/Table | matrix2table >> |