events2state: Multiple Event Variables to One State Variable
Description
Converts one or more event columns within a data frame to a single state vector whose values represent combinations of events.
Usage
events2state(data, events, number = TRUE, drop = TRUE, ...)
Value
Returns the input data frame with an added column called state.
Arguments
data
A data frame with relevant columns.
events
The names of the event variables as character strings in a vector.
number
A logical argument to determine whether the new state variable should be converted to a number representing the combination of events or left as is. Defaults to TRUE which will convert combinations a numeric. If argument is set to FALSE, the combinations will be left unchanged.
drop
Passed to interaction in order to determine whether unused factors will be excluded from the defining levels. The default is TRUE.
...
Further arguments to be passed to interaction.
Details
For a data frame with the necessary inputs, the function will aggregate values across columns supplied to events through the interaction function. The key for the different combination levels is printed to the console.