Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

replacedata - Class: dataset

Replace dataset variables

Syntax

B = replacedata(A,X)
B = replacedata(A,X,vars)

Description

B = replacedata(A,X) creates a dataset array B with the same variables as the dataset array A, but with the data for those variables replaced by the data in the array X. replacedata creates each variable in B using one or more columns from X, in order. X must have as many columns as the total number of columns in all of the variables in A, and as many rows as A has observations.

B = replacedata(A,X,vars) creates a dataset array B with the same variables as the dataset array A, but with the data for the variables specified in vars replaced by the data in the array X. The remaining variables in B are copies of the corresponding variables in A. vars 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. Each variable in B has as many columns as the corresponding variable in A. X must have as many columns as the total number of columns in all the variables specified in vars.

Examples

Use double or single as complementary operations with replacedata when processing variables outside of a dataset array:

data = dataset({rand(3,3),'Var1','Var2','Var3'})
data = 
    Var1       Var2       Var3   
    0.81472    0.91338     0.2785
    0.90579    0.63236    0.54688
    0.12699    0.09754    0.95751
X = double(data,'Var2');
X = zscore(X);
data = replacedata(data,X,'Var2')
data = 
    Var1       Var2       Var3   
    0.81472    0.88219     0.2785
    0.90579    0.20413    0.54688
    0.12699    -1.0863    0.95751

See Also

dataset

  


Recommended Products

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