Next: structures Up: MacAnova Help File Previous: stringplot()   Contents

structure()

Usage:
structure(var1 [,var2,...,vark] [, KeyPhrases]), where var1, var2, ...
  are arbitrary variables
KeyPhrases can be compnames:Name, labels:Labels, notes:Notes and
  silent:T, where Names, Notes, and Labels are CHARACTER scalars or
  vectors.  Arguments var1, ... can also be keyword phrases with keyword
  names other than 'compnames', 'labels', 'notes' and 'silent'.



Keywords: structures, combining variables
structure(var1,var2,....,vark) creates a structure with components named
var1, var2, ..., vark.  The values of the components are equal to var1,
etc.

structure() differs from strconcat() in that the any argument that is a
structure becomes a single component in the result, whereas strconcat()
splits it into its top level components, each of which become top level
components of the result.

When varj is a keyword phrase of the form name:value, the component is
named from the keyword.  For example, when a, b, and c are variables,
structure(a,b,c) and structure(a:a,b:b,c:c) are equivalent.  The names
should differ from the keyword names 'labels', 'notes', 'silent'
and 'compnames' recognized by structure().  See below for a work around.

When varj is a temporary variable, that is, a variable whose name starts
with '@', then the '@' is stripped off to create the name of the
component.  For example, when @x is defined, structure(@x,...) is the
same as structure(x:@x,...).

If varj is an expression or function result, for example "3+4" or "x'",
the component name will be NUMBER, LOGICAL, STRING, VECTOR, MATRIX,
ARRAY, STRUCTURE, MACRO, or GRAPH depending on the type and shape of the
component.

structure(var1, var2, ..., compnames:Names), where Names is a CHARACTER
vector or scalar, forms component names from Names, whose elements are
truncated to 12 characters, if necessary.  These take precedence over
other names as described above.  If Names is a scalar, say "Comp", it is
used as a root to create names of the form "Comp1", "Comp2", ... .
Otherwise the number of elements in Names must match the number of
components in the output.  This usage is particularly useful in
assigning names of 11 or 12 characters such as 'covariances" or
'factorloding'.

It is an error if any element of Names contains '$', a space or other
"invisible" character.

structure(var1, var2, ..., labels:Labels), where Labels is a CHARACTER
vector or scalar, labels the components using Labels.  If Labels is a
vector, then its length must match the number of components.  The labels
are printed instead of the component names on all output.  See topic
'labels'.  See strconcat() for information on how to add or remove
labels from an existing structure.

structure(var1, var2, ..., notes:Notes), where Notes is a CHARACTER
scalar or vector, attaches Notes as descriptive notes to the result.
See topic 'notes'.

You can suppress all warning messages by silent:T as in structure(x, y,
labels:vector("Height","Strength"), silent:T).

Keywords compnames, labels, notes, and silent must follow all arguments
that are to be included in the output structure.  If you want a
component with one of these names, either name it using keyword
'compnames' or make sure it is not the last component in the result.
For example, to have a component 'labels', use, say, structure(1,"A",
compnames:vector("x","labels")) or structure(labels:"A", x:1).

Example: You can create a structure with components min and max by
  Cmd> extremes <- structure(min:min(x), max:max(x))
by
  Cmd> @min <- min(x);@max <- max(x); extremes <- structure(@min,@max)
or by
  Cmd> extremes <- structure(min(x),max(x),\
        compnames:vector("min","max"))

In all three cases, to give a more complete labeling of the components
you can include an argument like labels:vector("Minimum of x", "Maximum
of x") .

See also topics strconcat() and 'structures'.


Gary Oehlert 2003-01-15