generate: Create a new variable

Description Usage Arguments Details Value Author(s) Examples

View source: R/mStats.R

Description

generate() creates a new variable either by deriving from existing variables or with a constant value.

Usage

1
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

1
2
3
4
5
6
7
8
9
## 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)

mStats documentation built on Nov. 23, 2020, 9:07 a.m.

Related to generate in mStats...