generate {mStats} | R Documentation |
Create a new variable
Description
generate()
creates a new variable either by
deriving from existing variables or with a constant value.
Usage
generate(data, var, expr = NULL)
Arguments
data |
data.frame |
var |
name for the new variable |
expr |
a constant value, name of an existing variable or an expression for simple arithmetic or logical operations: |
Details
The values of the variable are specified by expr
.
Label
The newly created variable is automatically labeled with the expression specified.
Value
data.frame with the new variable
Author(s)
Email: dr.myominnoo@gmail.com
Website: https://myominnoo.github.io/
Examples
## generate variable with a constant value
generate(mtcars, new_var, NA)
generate(mtcars, new_var, 99)
## generate variable from an existing variable
generate(mtcars, new_var, mpg)
## generate variable with arithmetic operations
generate(iris, Length, Sepal.Length + Petal.Length)
[Package mStats version 3.4.0 Index]