subset_apply: Subset and Apply Function

Description Usage Arguments Value Examples

View source: R/subset_apply.R

Description

Subset a data frame and apply a function to that portion of it defined by a column named batch

Usage

1
subset_apply(k, df, my_fun, seed = NULL)

Arguments

k

batch id to select

df

data frame to subset

my_fun

function to apply

seed

seed value to add to batch id, makes simulations reproducible. Default is NULL, don't set seed.

Value

output of function my_fun

Examples

1
2
3
4
5
6
7
8
9
test_df <- data.frame(batch=1:10, x=rnorm(10))
test_df
test_fun <- function(df) {df$y <- df$x * rnorm(1); return(df)}
test_fun(test_df)
test_fun(test_df[1:3,])
subset_apply(1, test_df, test_fun)
subset_apply(1, test_df, test_fun)
subset_apply(1, test_df, test_fun, seed=1001)
subset_apply(1, test_df, test_fun, seed=1001)

chapmandu2/pgxsim documentation built on May 6, 2019, 10:13 a.m.