Insert Column(s) into a Dataset

DESCRIPTION:

Inserts a new column (or columns) into a 2-dimensional dataset.

USAGE:

insert.col(target, target.column, count, column.type=<<see below>>, 
           column.names=NULL, fill.expression=<<see below>>, ...) 

REQUIRED ARGUMENTS:

target
2-dimensional dataset into which the new column(s) will be inserted.
target.column
integer or character (name-matching) value specifying the column of target at which the insertion is to be done; all existing columns of target, if any, from the insertion point to the last column will be shifted by count columns. To specify the last column of target plus one, use "@END", "", or a character value not matching any of the column names of target; in the latter case, target.column will be assigned to column.names if that argument is not supplied.
count
integer value specifying the number of columns to be inserted.

OPTIONAL ARGUMENTS:

column.type
character value specifying the data type to which the newly inserted column(s) will be coerced. Valid values are "dates", or anything for which paste("as", column.type, sep=".") exists. For matrices, column.type must be missing or the same as the data type of target; for other datasets, the default is the data type of fill.expression if supplied or "numeric" otherwise.
column.names
character vector specifying the name(s) for the newly inserted column(s). Default names will be generated if the length of column.names is less than count.
fill.expression
expression to use in supplying values for the newly inserted column(s). Expressions that reference a column name of target do not need to use subscripting (e.g., Weight > 3000 may be used instead of fuel.frame$Weight > 3000). The default is "" if column.type is "character", NA otherwise.

VALUE:

The target dataset with the newly inserted column(s).

SEE ALSO:

, , , , , , .

EXAMPLES:

# use air$ozone as fill.expression 
my.air <- insert.col(air, "@END", 1, column.names="HiOzone", fill=ozone > 4.0) 
# use "LoOzone" as column.name (it doesn't match any existing column names) 
my.air <- insert.col(my.air, "LoOzone", 1, fill=ozone < 2.0)