Learn R Programming

quickcode (version 1.0.6)

sample_by_column: Re-sample a dataset by column and return number of entry needed

Description

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)

Value

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

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

Examples

Run this code
data1 <- data.frame(ID=1:10,MOT=11:20)
sample_by_column(data1,MOT,3)
sample_by_column(data1,ID,7)

Run the code above in your browser using DataLab