copyMetadata#
Purpose#
Copies metadata from dataframe to dataset.
Format#
- x_meta = copyMetadata(X, src[, src_columns, X_columns])#
- Parameters:
X (NxK matrix) – data.
src (MxJ matrix) – Source of metadata.
src_columns (Lx1 vector or string array) – The names or indices of columns to copy metadata from. Default = all.
X_columns (Lx1 vector or string array) – The names or indices of columns to copy metadata to in X. Default = all.
- Returns:
x_meta (NxK dataframe) – Data in X with metadata from the specified columns in src attached.
Examples#
// Set random seed for replication
rndseed 80970;
// Load data with metadata
fname = getGAUSSHome("examples/auto2.dta");
auto2 = loadd(fname, "cat(rep78) + str(make)");
// Generate random data
X = rndi(150, 1, 1|5);
// Copy metadata from 'rep78' in 'auto2' to 'X'
X = copymetadata(X, auto2, "rep78");
The code above copies the metadata from the categorical variable rep78 to the matrix X. After the code the first five rows of x look like:
Average
Poor
X[1:5, .] = Poor
Good
Fair
See also
Functions dfname()
, setColLabels()
, dftype()
, asdate()