Learn R Programming

simstudy (version 0.9.0)

addDataDensity: Add data from a density defined by a vector of integers

Description

Data are generated from an a density defined by a vector of integers.

Usage

addDataDensity(dtOld, dataDist, varname, uselimits = FALSE, na.rm = TRUE)

Value

A data table with the generated data.

Arguments

dtOld

Name of data table that is to be updated.

dataDist

Numeric vector. Defines the desired density.

varname

Character. Name of the variable.

uselimits

Logical. If TRUE, the minimum and maximum of the input data vector are used as limits for sampling. Defaults to FALSE, in which case a smoothed density that extends beyond these limits is used.

na.rm

Logical. If TRUE (default), missing values in `dataDist` are removed. If FALSE, the data will retain the same proportion of missing values.

Examples

Run this code
def <- defData(varname = "x1", formula = 5, dist = "poisson")

data_dist <- data_dist <- c(1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 7, 7, 7, 8, 9, 10, 10)

dd <- genData(500, def)
dd <- addDataDensity(dd, data_dist, varname = "x2")
dd <- addDataDensity(dd, data_dist, varname = "x3", uselimits = TRUE)

Run the code above in your browser using DataLab