expand: expand

Description Usage Arguments Author(s) Examples

Description

The expand function is similar to the function of the same name available in Stata. Given a dataset, and an expansion factor N, expand will output all rows in a data frame, repeated N times each.

Usage

1
expand(dataset, size)

Arguments

dataset

A data frame or matrix to expand.

size

Number of times each row should be output in the resulting data frame or matrix.

Author(s)

Ryan Patrick Kyle <ryan.kyle@mail.mcgill.ca>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## The function is currently defined as
function (dataset, size) 
{
    size <- abs(size)
    if (!(all(floor(size) == size, na.rm = TRUE) & length(size) == 
        1)) {
        stop("argument size must be an integer of length 1!")
    }
    return(dataset[rep(1:nrow(dataset), each = size), ])
  }

rpkyle/epimisc documentation built on May 31, 2019, 5:43 a.m.