asdf#

Purpose#

Adds metadata to a matrix or string array and returns a dataframe.

Format#

x_meta = asdf(x[, varname_1[, varname_2[, ...]]])#
Parameters:
  • x (NxK matrix or string array) – data.

  • ... (string) – Optional arguments, comma separated list of variable names.

Returns:

x_meta (NxK dataframe) – data.

Examples#

Example 1#

// Randomly generate linear data
nobs = 100;
x_t = rndn(nobs, 1);
e_t = rndn(nobs, 1);
y_t = 1.3 + 2*x_t + e_t;

// Convert to a dataframe
// and add variable names
linear_data = asdf(y_t ~ x_t ~ e_t, "Y", "X", "Error");

After the above code, linear_data is a dataframe with three numeric variables named Y, X, and Error:

_images/asdf-cr-2.jpg

Example 2#

// Create string array of data
string x_sa = {"cat", "dog", "bird", "cat", "bird", "fish"};

// Convert to a dataframe
// and name the variable `Animals`
x_df = asdf(x_sa, "Animals");

After the above code, x_df is a dataframe with one categorical variable named Animals:

_images/asdf-cr-1.jpg

Remarks#

See also

Functions asMatrix(), asDate(), dfname(), dftype()