columns {strvalidator} | R Documentation |
Column Actions
Description
Perform actions on columns.
Usage
columns(
data,
col1 = NA,
col2 = NA,
operator = "&",
fixed = NA,
target = NA,
start = 1,
stop = 1,
debug = FALSE
)
Arguments
data |
a data frame. |
col1 |
character column name to perform action on. |
col2 |
character optional second column name to perform action on. |
operator |
character to indicate operator: '&' concatenate, '+' add, '*' multiply, '-' subtract, '/' divide, 'substr' extract a substring. |
fixed |
character or numeric providing the second operand if 'col2' is not used. |
target |
character to specify column name for result. Default is to overwrite 'col1'. If not present it will be added. |
start |
integer, the first position to be extracted. |
stop |
integer, the last position to be extracted. |
debug |
logical to indicate if debug information should be printed. |
Details
Perform actions on columns in a data frame. There are five actions: concatenate, add, multiply, subtract, divide. The selected action can be performed on two columns, or one column and a fixed value, or a new column can be added. A target column for the result is specified. NB! if the target column already exist it will be overwritten, else it will be created. A common use is to create a unique Sample.Name from the existing Sample.Name column and e.g. the File.Name or File.Time columns. It can also be used to calculate the Amount from the Concentration.
Value
data frame.
See Also
Examples
# Get a sample dataset.
data(set2)
# Add concatenate Sample.Name and Dye.
set2 <- columns(data = set2, col1 = "Sample.Name", col2 = "Dye")
# Multiply Height by 4.
set2 <- columns(data = set2, col1 = "Height", operator = "*", fixed = 4)
# Add a new column.
set2 <- columns(data = set2, operator = "&", fixed = "1234", target = "Batch")