These function are only to be used cosmetically before kable and will likely return a data frame with duplicate names.

rename_redundant(x, ...)

augment_redundant(x, ...)

Arguments

x

a data frame

...

a series of keys and values to replace columns that match specific patterns.

Value

a data frame.

Details

  • rename_redundant fully replaces any column names matching the keys

  • augment_redundant will take a regular expression and rename columns via gsub().

Examples

df <- data.frame( x = letters[1:10], `a n` = 1:10, `a prop` = (1:10) / 10, `a deff` = round(pi, 2), `b n` = 10:1, `b prop` = (10:1) / 10, `b deff` = round(pi * 2, 2), check.names = FALSE ) df
#> x a n a prop a deff b n b prop b deff #> 1 a 1 0.1 3.14 10 1.0 6.28 #> 2 b 2 0.2 3.14 9 0.9 6.28 #> 3 c 3 0.3 3.14 8 0.8 6.28 #> 4 d 4 0.4 3.14 7 0.7 6.28 #> 5 e 5 0.5 3.14 6 0.6 6.28 #> 6 f 6 0.6 3.14 5 0.5 6.28 #> 7 g 7 0.7 3.14 4 0.4 6.28 #> 8 h 8 0.8 3.14 3 0.3 6.28 #> 9 i 9 0.9 3.14 2 0.2 6.28 #> 10 j 10 1.0 3.14 1 0.1 6.28
print(df <- rename_redundant(df, "%" = "prop", "Design Effect" = "deff"))
#> x a n % Design Effect b n % Design Effect #> 1 a 1 0.1 3.14 10 1.0 6.28 #> 2 b 2 0.2 3.14 9 0.9 6.28 #> 3 c 3 0.3 3.14 8 0.8 6.28 #> 4 d 4 0.4 3.14 7 0.7 6.28 #> 5 e 5 0.5 3.14 6 0.6 6.28 #> 6 f 6 0.6 3.14 5 0.5 6.28 #> 7 g 7 0.7 3.14 4 0.4 6.28 #> 8 h 8 0.8 3.14 3 0.3 6.28 #> 9 i 9 0.9 3.14 2 0.2 6.28 #> 10 j 10 1.0 3.14 1 0.1 6.28
print(df <- augment_redundant(df, " (n)" = " n$"))
#> x a (n) % Design Effect b (n) % Design Effect #> 1 a 1 0.1 3.14 10 1.0 6.28 #> 2 b 2 0.2 3.14 9 0.9 6.28 #> 3 c 3 0.3 3.14 8 0.8 6.28 #> 4 d 4 0.4 3.14 7 0.7 6.28 #> 5 e 5 0.5 3.14 6 0.6 6.28 #> 6 f 6 0.6 3.14 5 0.5 6.28 #> 7 g 7 0.7 3.14 4 0.4 6.28 #> 8 h 8 0.8 3.14 3 0.3 6.28 #> 9 i 9 0.9 3.14 2 0.2 6.28 #> 10 j 10 1.0 3.14 1 0.1 6.28