Learn R Programming

mStats (version 3.2.2)

expand2: Duplicate observations within a dataframe

Description

expand2 generates duplicated observations within a dataframe.

Usage

expand2(data, n_n = NULL, copies = 2, original = TRUE)

Arguments

data

a data frame object

n_n

index or indexes specifying row numbers

copies

desired number of copies

original

a logical indicating whether to keep the original dataframe

Value

data.frame

Details

expand2 appends observations from the dataframe with n copies of the observations with specified indexes of observations or all data.

Examples

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

## create duplicates
infert.new <- expand2(infert, 1:5, copies = 2)
codebook(infert.new)


## check duplicates report and rmeove dup
infert.dupremove <- duplicates(infert.new, drop = TRUE)
codebook(infert.dupremove)

## remove only 3 copies
infert.3copies <- duplicates(infert.new)
tab(infert.3copies, dup)

infert.3copies <- filter(infert.3copies, dup < 2)
codebook(infert.3copies)

# }

Run the code above in your browser using DataLab