Skip to contents

Return a sampled subset of this SparkDataFrame using a random seed. Note: this is not guaranteed to provide exactly the fraction specified of the total count of of the given SparkDataFrame.

Usage

sample(x, withReplacement = FALSE, fraction, seed)

sample_frac(x, withReplacement = FALSE, fraction, seed)

# S4 method for SparkDataFrame
sample(x, withReplacement = FALSE, fraction, seed)

# S4 method for SparkDataFrame
sample_frac(x, withReplacement = FALSE, fraction, seed)

Arguments

x

A SparkDataFrame

withReplacement

Sampling with replacement or not

fraction

The (rough) sample target fraction

seed

Randomness seed value. Default is a random seed.

Note

sample since 1.4.0

sample_frac since 1.4.0

Examples

if (FALSE) {
sparkR.session()
path <- "path/to/file.json"
df <- read.json(path)
collect(sample(df, fraction = 0.5))
collect(sample(df, FALSE, 0.5))
collect(sample(df, TRUE, 0.5, seed = 3))
}