expand2: Duplicate observations within a dataframe

Description Usage Arguments Details Author(s) See Also Examples

View source: R/expand2.R

Description

expand2 generates duplicated observations within a dataframe.

Usage

1
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

Details

expand2

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

Author(s)

Myo Minn Oo (Email: dr.myominnoo@gmail.com | Website: https://myominnoo.github.io/)

See Also

keep, generate, egen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 

#### Ref:
# HOW CAN I DETECT DUPLICATE OBSERVATIONS? | STATA FAQ
# from https://stats.idre.ucla.edu/stata/faq/how-can-i-detect-duplicate-observations-3/
# (accessed September 27, 2019).

required(haven)
# install.packages("haven")
hsb2 <- read_dta("https://stats.idre.ucla.edu/stat/stata/notes/hsb2.dta")
str(hsb2)
hsb2.new <- expand2(hsb2, 1:5, 4)
hsb2.new <- expand2(hsb2, 1:5, 4, original = FALSE)

## End(Not run)

myominnoo/mStats_beta documentation built on Feb. 29, 2020, 8:17 a.m.