Learn R Programming

tidyfst (version 0.8.8)

sample_dt: Sample n rows from a table

Description

Analogous function for sample_n and sample_frac in dplyr.

sample_dt is a merged version of sample_n_dt and sample_frac_dt, this could be convenient.

Usage

sample_dt(data, n = NULL, prop = NULL, replace = FALSE)

sample_n_dt(data, size, replace = FALSE)

sample_frac_dt(data, size, replace = FALSE)

Arguments

data

A data.frame

n

Number of rows to select

prop

Fraction of rows to select

replace

Sample with or without replacement? Default uses FALSE.

size

For sample_n_dt, the number of rows to select. For sample_frac_dt, the fraction of rows to select.

Value

data.table

See Also

sample_n,sample_frac

Examples

Run this code
# NOT RUN {
sample_n_dt(mtcars, 10)
sample_n_dt(mtcars, 50, replace = TRUE)
sample_frac_dt(mtcars, 0.1)
sample_frac_dt(mtcars, 1.5, replace = TRUE)

sample_dt(mtcars,n=10)
sample_dt(mtcars,prop = 0.1)

# }

Run the code above in your browser using DataLab