epi_clean_spread_repeated: Spread repeated observations

View source: R/epi_clean_spread_repeated.R

epi_clean_spread_repeatedR Documentation

Spread repeated observations

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

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 <\url{https://github.com/AntonioJBT/episcout}>

See Also

epi_clean_add_colname_suffix, epi_clean_merge_nested_dfs, epi_clean_transpose

Examples


## 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 Dec. 1, 2024, 4:07 a.m.