resample: Randomly changing the order of obersverations

Description Usage Arguments Value Examples

View source: R/resample.R

Description

This function randomly resamples observations separately for variables and groups (e.g., individual participants) so that meaningful information contained in the order of the observation gets lost, but each groups still has the same set of values.

Usage

1
resample(data, ID, variables)

Arguments

data

A data frame containing hierarchical data (e.g., time series data)

ID

The grouping variable (e.g., to distinguish participants from each other)

variables

A vector of variable names for which the order should be changed.

Value

The resampled data frame.

Examples

1
2
3
4
5
6
tib  <- dplyr::tibble(participant=rep(1:10, each=10),  # grouping variable
happiness = rnorm(100, mean = 3.5, sd=1.7),     # order should not be changed
stress = rnorm(100, mean = 2, sd= 1.3),         # order should be changed
anxiety = rnorm(100, mean = 1.7, sd= 2))        # order should be changed

new_tib <- resample(tib, participant, c("stress", "anxiety"))

anabelbue/dynamicpack documentation built on Dec. 19, 2021, 2:32 a.m.