epi_clean_add_colname_suffix: Add a suffix to column names

View source: R/epi_clean_add_colname_suffix.R

epi_clean_add_colname_suffixR Documentation

Add a suffix to column names

Description

Add a suffix to column names except for an ID header. Useful if changing labels to include eg baseline, time_1, time_2, etc.

Usage

epi_clean_add_colname_suffix(df = NULL, id_col_num = 1, suffix = "")

Arguments

df

A dataframe object with headers

id_col_num

Column number to exclude, usually the ID variable. Default is 1.

suffix

String to add as a suffix to each column except id_col_num

Value

String of column names with suffix added. Change headers manually with these.

Author(s)

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

See Also

epi_clean_add_rep_num, epi_clean_get_dups, epi_clean_spread_repeated

Examples


## Not run: 
n <- 20
df2 <- 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)
)
# df2
names(df2)
# Add .0 as suffix to all column names starting from column 2 (skip id col):
id_col <- 1
new_colnames <- epi_clean_add_colname_suffix(df2, id_col, '.0')
new_colnames
# Rename them in my data frame:
names(df2)[-id_col] <- new_colnames
names(df2)

## End(Not run)


AntonioJBT/episcout documentation built on Dec. 1, 2024, 4:07 a.m.