Skip to contents

Shorthand to return a re-sample number of rows in a data frame by unique column

Usage

sample_by_column(.dt, col, n, seed = NULL, replace = FALSE)

Arguments

.dt

data frame to re-sample

col

column to uniquely re-sample

n

number of rows to return

seed

unique numeric value for reproducibility

replace

should sampling be with replacement

Value

data frame containing re-sampled rows from an original data frame

Examples

data1 <- data.frame(ID=1:10,MOT=11:20)
sample_by_column(data1,MOT,3)
#> Warning: Work on function still in progress. Use with caution.
#>    ID MOT
#> 2   2  12
#> 4   4  14
#> 10 10  20
sample_by_column(data1,ID,7)
#> Warning: Work on function still in progress. Use with caution.
#>    ID MOT
#> 2   2  12
#> 4   4  14
#> 5   5  15
#> 6   6  16
#> 7   7  17
#> 8   8  18
#> 10 10  20