epi_clean_transpose: Transposes a dataframe preserving row and column names

View source: R/epi_clean_transpose.R

epi_clean_transposeR Documentation

Transposes a dataframe preserving row and column names

Description

Transposes a dataframe preserving row and column names. Based on data.table transpose. Assumes there is an id column with unique IDs

Usage

epi_clean_transpose(df = NULL, id_col_num = "")

Arguments

df

A dataframe object to transpose. Coerced to data.table and returned as data.frame.

id_col_num

Index to identify the column with IDs

Value

A transposed dataframe with the first column containing the transposed values of the column passed as id_col_num.

Author(s)

Antonio Berlanga-Taylor <\url{https://github.com/AntonioJBT/episcout}>

See Also

epi_clean_add_colname_suffix, epi_clean_spread_repeated, epi_clean_merge_nested_dfs, transpose, as.data.table.

Examples


## Not run: 
library(data.table)
# Generate some data:
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$id_col <- rownames(df)
df
id_col <- 6
df_t <- epi_clean_transpose(df = df, id_col)
class(df_t)
dim(df)
dim(df_t)
df_t
names(df_t)

## End(Not run)


AntonioJBT/episcout documentation built on June 8, 2024, 7:47 a.m.