Description Usage Arguments Examples
This simple function allows for simple operations to be performed on sets of variables within a dataframe. It is useful mainly for maintaining code consistency and saving subsetting code. It can add, divide, multiply and subtract by a constant, and will perform the same operation on all variables passed in.
1 | operate_cols(data, variables, operation = "add", number)
|
data |
The input dataset |
variables |
A character vector of variables to be operated on |
operation |
one of 'add', 'subtract', 'multiply', 'divide' |
number |
A constant. This should usually be positive (subtract will automatically flip it), and will make sense to say out loud "subtract 2" rather than "subtract -2" is usually what is intended. Of course, you can multiply by -4, if for some reason you so wish... |
1 2 | # Subtract one from the carb column of mtcars
operate_cols(mtcars, 'carb', 'subtract', 1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.