Skip to contents

Subset rows randomly

Usage

# S3 method for flowFrame
slice_sample(.data, ..., n, prop, by = NULL, weight_by = NULL, replace = FALSE)

Arguments

.data

A flowFrame

...

Unused.

n, prop

Provide either n, the number of rows, or prop, the proportion of rows to select. If neither are supplied, n = 1 will be used. If n is greater than the number of rows in the group (or prop > 1), the result will be silently truncated to the group size. prop will be rounded towards zero to generate an integer number of rows.

A negative value of n or prop will be subtracted from the group size. For example, n = -2 with a group of 5 rows will select 5 - 2 = 3 rows; prop = -0.25 with 8 rows will select 8 * (1 - 0.25) = 6 rows.

by

Optionally, an unquoted selection of columns to group by for just this operation. An alternative to group_by.

weight_by

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

replace

Should sampling be performed with (TRUE) or without (FALSE, the default) replacement.

Value

An object of the same type as .data. The output has the following properties: * Each row may appear 0, 1, or many times in the output. * Columns are not modified. * Groups are not modified. * A flowFrame's identifier is preserved.

Examples


my_flowframe <- simulate_cytometry_data()$flowframe

 my_flowframe |>
   dplyr::slice_sample(n = 5)
#> flowFrame object 'V1'
#> with 5 cells and 10 observables:
#>            name       desc     range  minRange  maxRange
#> $P1   feature_1  feature_1        67         0        66
#> $P2   feature_2  feature_2        78         0        77
#> $P3   feature_3  feature_3        95         0        94
#> $P4   feature_4  feature_4        74         0        73
#> $P5   feature_5  feature_5        94         0        93
#> $P6   feature_6  feature_6        72         0        71
#> $P7   feature_7  feature_7       101         0       100
#> $P8   feature_8  feature_8        78         0        77
#> $P9   feature_9  feature_9        87         0        86
#> $P10 feature_10 feature_10        96         0        95
#> 88 keywords are stored in the 'description' slot