Skip to contents

Select a random sample of rows/columns

Usage

# S3 method for class 'tidymatrix'
slice_sample(.data, n, prop, weight_by = NULL, replace = FALSE, ...)

Arguments

.data

A tidymatrix object

n

Number of rows/columns to select

prop

Proportion of rows/columns to select

weight_by

Sampling weights (not yet implemented)

replace

Sample with replacement

...

Not used

Value

A tidymatrix object with sampled data

Examples

library(dplyr, warn.conflicts = FALSE)
tm <- tidymatrix(big5_responses, big5_respondents, big5_items)

tm |>
  activate(rows) |>
  slice_sample(n = 20)
#> # A tidymatrix: 20 x 30 matrix
#> # Active: rows
#> #
#> # Row data: 20 rows x 8 columns
#> # Column data: 30 rows x 5 columns
#> #
#> # Active data (rows):
#>   respondent_id age gender education     occupation country life_satisfaction
#> 1          R278  55   Male Secondary         Office      LT                 5
#> 2          R174  55   Male  Bachelor   Professional      LV                 6
#> 3          R094  60 Female  Bachelor        Retired      SE                10
#> 4          R332  31 Female  Bachelor Service/Manual      EE                 6
#> 5          R265  57   Male     Basic     Unemployed      LT                 8
#> 6          R354  39 Female    Master         Office      EE                 7
#>   completion_min
#> 1            9.7
#> 2           11.4
#> 3            7.1
#> 4            4.1
#> 5           10.9
#> 6            6.3