knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(dsamplr)

The dsamplr package provides a simple interface for sampling from a chosen statistical distribution. It allows the user to specify:

The package defines an S3 class object 'dsamplr' with a specified summary method.

Examples

Sample 10 random draws from a normal distribution

dsamplr(10, "normal")

Sample 100 draws from a poisson distribution with lambda = 10

dsamplr(10, "poisson", lambda = 10)

The documentation for the underlying base R functions rnorm, rpois and rbinom provide more information on permitted inputs.

dsamplr class

The output is returned as an S3 object of class 'dsamplr'. This is simply a list with samples stored at $sample and the distribution stored at $distribution. A summary method is also defined as shown below.

draw <- dsamplr(100, "normal")

draw$sample

draw$distribution

summary(draw)

Pitfalls

Make sure to input the distribution as a string. Avoid the following:

dsamplr(100, normal)


kmeteyard/dsamplr documentation built on May 21, 2019, 1:44 p.m.