View source: R/epi_clean_transpose.R
epi_clean_transpose | R Documentation |
Transposes a dataframe preserving row and column names. Based on data.table transpose. Assumes there is an id column with unique IDs
epi_clean_transpose(df = NULL, id_col_num = "")
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 |
A transposed dataframe with the first column containing the transposed values of the column passed as id_col_num.
Antonio Berlanga-Taylor <\url{https://github.com/AntonioJBT/episcout}>
epi_clean_add_colname_suffix
,
epi_clean_spread_repeated
,
epi_clean_merge_nested_dfs
,
transpose
,
as.data.table
.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.