Learn R Programming

mStats (version 3.2.2)

generate: Create a new variable

Description

generate() creates a new variable within the data frame

Usage

generate(data, var, .expr = NULL)

Arguments

data

Dataset

var

New variable

.expr

value or Expression for simple arithmetic or logical operations: See examples.

Details

If the data is specified, it returns modified dataset with newly created variable. The value of the variable are specified by expr argument.

Examples

Run this code
# NOT RUN {
## use infert data
data(infert)
codebook(infert)

## create a new variable induced2 with 0 and 1+2
infert.new <- generate(infert, induced2, as.numeric(induced == 0))
tab(infert.new, induced2)

## create a new variable with values the same as education
infert.new <- generate(infert, edu, education)
tab(infert.new, edu)

# }

Run the code above in your browser using DataLab