interleave: Interleave two dataframes

Description Usage Arguments Value Examples

View source: R/processSimulations.R

Description

The interleave function takes in two data frames, x and y. It interleaves every row in x with every n rows in y. That is, the first row of x is followed by n rows of y, and then the next row of x, and then the next n rows of y, etc.

The interleave function – specific to this package – adds two columns, experience and row that describe contain the source of experience (real or simulated) and the row number from each dataframe.

This is used in the processSimData function.

Usage

1
interleave(x, y, n)

Arguments

x

The dataframe whose data should be in the first row.

y

The dataframe whose data should be interleaved with parameter x.

n

The amount of rows in y to follow each row in x. Should be divisible by y.

Value

A dataframe of length x + y.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
#Interleave by every row:
yesData <- dplyr::tibble("response" = base::rep("yes", 5))
noData <- dplyr::tibble("response" = base::rep("no", 5))

responseData <- interleave(x = yesData, y = noData, n = 1)

#Interleave by every 2 rows
firstSet <- dplyr::tibble("data" = base::seq(1,10))
secondSet <- dplyr::tibble("data" = base::seq(1,20))

interleave(x = firstSet, y = secondSet, n = 2)

## End(Not run)

jdtrat/dynaq documentation built on July 24, 2020, 7:18 a.m.