epi_clean_spread_repeated: Spread repeated observations

Description Usage Arguments Value Author(s) See Also Examples

View source: R/epi_clean_spread_repeated.R

Description

Create a single data frame with unique rows (individuals) and repeated observations across columns. A column with the replicate/repeated observation/time-point number for each row must be provided.

Usage

1
epi_clean_spread_repeated(df = NULL, rep_col = "", id_col_num = 1)

Arguments

df

A dataframe in long format

rep_col

Column index or string to use to base spread on.

id_col_num

Column index with ID values. Default is 1.

Value

a nested list with as many sub-lists as unique values contained in the column passed as rep_col. Column headers are renamed using epi_clean_add_colname_suffix and will contain suffixes taken from the unique values in rep_col. The ID column passed as id_col_num is included in each sub-list.

Author(s)

Antonio Berlanga-Taylor <https://github.com/AntonioJBT/episcout>

See Also

epi_clean_add_colname_suffix, epi_clean_merge_nested_dfs, epi_clean_transpose

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
n <- 20
df <- data.frame(
var_id = rep(1:(n / 2), each = 2),
var_to_rep = rep(c('Pre', 'Post'), n / 2),
  x = rnorm(n),
  y = rbinom(n, 1, 0.50),
  z = rpois(n, 2)
)
df
df_spread <- epi_clean_spread_repeated(df, 'var_to_rep', 1)
# Returns a nested list:
df_spread

## End(Not run)

AntonioJBT/episcout documentation built on Nov. 7, 2019, 5:34 p.m.