| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Statistics Toolbox |
| Contents | Index |
| Learn more about Statistics Toolbox |
Merge observations
C = join(A,B)
C = join(A,B,key)
C = join(A,B,param1,val1,param2,val2,...)
[C,IB] = join(...)
C = join(A,B,'Type',TYPE,...)
[C,IA,IB] = join(A,B,'Type',TYPE,...)
C = join(A,B) creates a dataset array C by merging observations from the two dataset arrays A and B. join performs the merge by first finding key variables, that is, a pair of dataset variables, one in A and one in B, that share the same name. The key from B must contain unique values, and must contain all the values that are present in the key from A. join then uses these key variables to define a many-to-one correspondence between observations in A and those in B. join uses this correspondence to replicate the observations in B and combine them with the observations in A to create C.
C = join(A,B,key) performs the merge using the variable specified by key as the key variable in both A and B. key is a positive integer, a variable name, a cell array containing a variable name, or a logical vector with one true entry.
C contains one observation for each observation in A. Variables in C include all of the variables from A, as well as one variable corresponding to each variable in B (except for the key from B). If A and B contain variables with identical names, join adds the suffix '_left' and '_right' to the corresponding variables in C.
C = join(A,B,param1,val1,param2,val2,...) specifies optional parameter name/value pairs to control how the dataset variables in A and B are used in the merge. Parameters are:
'Keys' — Specifies the variable to use as a keys in both A and B.
'LeftKeys' — Specifies the variable to use as a keys in A.
'RightKeys' — Specifies the variable to use as a keys in B.
You may provide either the 'Keys' parameter, or both the 'LeftKeys' and 'RightKeys' parameters. The value for these parameters is a positive integer, a variable name, a cell array containing a variable name, or a logical vector with one true entry. 'LeftKeys' or 'RightKeys' must both specify the same number of key variables, and join pairs the left and right keys are paired in the order specified.
'LeftVars' — Specifies the variables from A to include in C. By default, join includes all variables from A.
'RightVars' — Specifies the variables from B to include in C. By default, join includes all variables from B except the key variable.
The value for these parameters is a positive integer, a vector of positive integers, a variable name, a cell array containing one or more variable names, or a logical vector.
[C,IB] = join(...)returns an index vector IB, where join constructs C by horizontally concatenating A(:,LeftVars) and B(IB,RightVars). join can also perform more complicated inner and outer join operations that allow a many-to-many correspondence between A and B, and allow unmatched observations in either A or B.
C = join(A,B,'Type',TYPE,...)performs the join operation specified by TYPE. TYPE is one of 'inner', 'leftouter', 'rightouter', 'fullouter', or 'outer' (which is a synonym for 'fullouter'). For an inner join, C only contains observations corresponding to a combination of key values that occurred in both A and B. For a left (or right) outer join, C also contains observations corresponding to keys in A (or B) that did not match any in B (or A). Variables in C taken from A (or B) contain null values in those observations. A full outer join is equivalent to a left and right outer join. C contains variables corresponding to the key variables from both A and B, and join sorts the observations in C by the key values.
For inner and outer joins, C contains variables corresponding to the key variables from both A and B by default, as well as all the remaining variables. join sorts the observations in the result C by the key values.
[C,IA,IB] = join(A,B,'Type',TYPE,...) returns index vectors IA and IB indicating the correspondence between observations in C and those in A and B. For an inner join, join constructs C by horizontally concatenating A(IA,LeftVars) and B(IB,RightVars). For an outer join, IA or IB may also contain zeros, indicating the observations in C that do not correspond to observations in A or B, respectively.
Create a dataset array from Fisher's iris data:
load fisheriris
NumObs = size(meas,1);
NameObs = strcat({'Obs'},num2str((1:NumObs)','%-d'));
iris = dataset({nominal(species),'species'},...
{meas,'SL','SW','PL','PW'},...
'ObsNames',NameObs);
Create a separate dataset array with the diploid chromosome counts for each species of iris:
snames = nominal({'setosa';'versicolor';'virginica'});
CC = dataset({snames,'species'},{[38;108;70],'cc'})
CC =
species cc
setosa 38
versicolor 108
virginica 70Broadcast the data in CC to the rows of iris using the key variable species in each dataset:
iris2 = join(iris,CC);
iris2([1 2 51 52 101 102],:)
ans =
species SL SW PL PW cc
Obs1 setosa 5.1 3.5 1.4 0.2 38
Obs2 setosa 4.9 3 1.4 0.2 38
Obs51 versicolor 7 3.2 4.7 1.4 108
Obs52 versicolor 6.4 3.2 4.5 1.5 108
Obs101 virginica 6.3 3.3 6 2.5 70
Obs102 virginica 5.8 2.7 5.1 1.9 70![]() | johnsrnd | Kernel property (ProbDistKernel) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |