sample_n()
and sample_frac()
have been superseded in favour of
slice_sample()
. While they will not be deprecated in the near future,
retirement means that we will only perform critical bug fixes, so we recommend
moving to the newer alternative.
These functions were superseded because we realised it was more convenient to
have two mutually exclusive arguments to one function, rather than two
separate functions. This also made it to clean up a few other smaller
design issues with sample_n()
/sample_frac
:
The connection to slice()
was not obvious.
The name of the first argument, tbl
, is inconsistent with other
single table verbs which use .data
.
The size
argument uses tidy evaluation, which is surprising and
undocumented.
It was easier to remove the deprecated .env
argument.
...
was in a suboptimal position.
# S3 method for class 'SingleCellExperiment'
sample_n(tbl, size, replace = FALSE, weight = NULL, .env = NULL, ...)
# S3 method for class 'SingleCellExperiment'
sample_frac(tbl, size = 1, replace = FALSE, weight = NULL, .env = NULL, ...)
A data.frame.
<tidy-select
>
For sample_n()
, the number of rows to select.
For sample_frac()
, the fraction of rows to select.
If tbl
is grouped, size
applies to each group.
Sample with or without replacement?
<tidy-select
> 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.
DEPRECATED.
ignored
`tidySingleCellExperiment`
data(pbmc_small)
pbmc_small |> sample_n(50)
#> # A SingleCellExperiment-tibble abstraction: 50 × 17
#> # Features=230 | Cells=50 | Assays=counts, logcounts
#> .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
#> <chr> <fct> <dbl> <int> <fct> <fct> <chr>
#> 1 CTGC… SeuratPro… 146 47 0 A g1
#> 2 GCGC… SeuratPro… 213 48 1 B g2
#> 3 GAGT… SeuratPro… 527 47 0 A g1
#> 4 CATA… SeuratPro… 286 68 0 A g1
#> 5 AAGC… SeuratPro… 126 48 0 A g1
#> 6 CTAA… SeuratPro… 246 59 0 A g1
#> 7 GATA… SeuratPro… 328 72 1 B g1
#> 8 ATCA… SeuratPro… 168 37 0 A g2
#> 9 AATG… SeuratPro… 389 73 1 B g1
#> 10 AGTC… SeuratPro… 173 53 0 A g2
#> # ℹ 40 more rows
#> # ℹ 10 more variables: RNA_snn_res.1 <fct>, file <chr>, ident <fct>,
#> # PC_1 <dbl>, PC_2 <dbl>, PC_3 <dbl>, PC_4 <dbl>, PC_5 <dbl>, tSNE_1 <dbl>,
#> # tSNE_2 <dbl>
pbmc_small |> sample_frac(0.1)
#> # A SingleCellExperiment-tibble abstraction: 8 × 17
#> # Features=230 | Cells=8 | Assays=counts, logcounts
#> .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
#> <chr> <fct> <dbl> <int> <fct> <fct> <chr>
#> 1 CCATC… SeuratPro… 224 50 1 B g2
#> 2 CGGCA… SeuratPro… 94 55 0 A g2
#> 3 TTACG… SeuratPro… 228 39 0 A g1
#> 4 TACTC… SeuratPro… 156 48 0 A g1
#> 5 CATGG… SeuratPro… 85 52 0 A g1
#> 6 GAACC… SeuratPro… 87 50 1 B g2
#> 7 ACAGG… SeuratPro… 151 59 0 A g1
#> 8 GATAG… SeuratPro… 328 72 1 B g1
#> # ℹ 10 more variables: RNA_snn_res.1 <fct>, file <chr>, ident <fct>,
#> # PC_1 <dbl>, PC_2 <dbl>, PC_3 <dbl>, PC_4 <dbl>, PC_5 <dbl>, tSNE_1 <dbl>,
#> # tSNE_2 <dbl>