| Contents | Index |
Replace dataset variables
B = replacedata(A,X)
B = replacedata(A,X,vars)
B = replacedata(A,fun)
B =
replacedata(A,fun,vars)
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.
B = replacedata(A,fun) or B = replacedata(A,fun,vars) creates a dataset array B by applying the function fun to the values in A's variables. replacedata first horizontally concatenates A's variables into a single array, then applies the function fun. The specified variables in A must have types and sizes compatible with the concatenation. fun is a function handle that accepts a single input array and returns an array with the same number of rows and columns as the input.
data = dataset({rand(3,3),'Var1','Var2','Var3'})
% Use ZSCORE to normalize each variable in a dataset array
% separately, by explicitly extracting and transforming the
% data, and then replacing it.
X = double(data);
X = zscore(X);
data = replacedata(data,X)
% Equivalently, provide a handle to ZSCORE.
data = replacedata(data,@zscore)
% Use ZSCORE to normalize each observation in a dataset
% array separately by creating an anonymous function.
data = replacedata(data,@(x) zscore(x,[],2))
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |