sample_all_or_n: Sample a dataframe for n obs and returns full dataframe if n...

Description Usage Arguments See Also Examples

View source: R/sample.R

Description

Sample a dataframe for n obs and returns full dataframe if n > nrow

Usage

1

Arguments

data

A dataframe or tibble.

n

Number of rows to sample. If n is greater than the row count, the dataframe will be returned unchanged.

replace

Sample with or without replacement?

weight

Sampling weights. This must evaluate to a vector of non-negative numbers the same length as the input. Weights are automatically standardised to sum to 1.

See Also

sample_n

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(tidyverse)
test_data <- 
        tibble(
                Group = sample(c("Apple", "Pear"), size = 10, replace = TRUE),
                A     = sample(c(NA_integer_, 1:3), size = 10, replace = TRUE),
                B     = sample(c(NA_integer_, 4:6), size = 10, replace = TRUE)
        )


# Sample less than row count
sample_all_or_n(data = test_data,
                n = 5)

# When n is greater than row count, the dataframe is returned unchanged
sample_all_or_n(data = test_data,
                n = 11)

meerapatelmd/rubix documentation built on Sept. 5, 2021, 8:30 p.m.