Add Suffix to Column Names
Arguments
- data
data frame
- suffix
suffix to be added to each column name except the columns given in
except
- except
names of columns to which no suffix is to be given
Examples
d1 <- data.frame(id = 1, a = 2, b = 3)
d2 <- data.frame(id = 1, c = 2, d = 3)
# Using merge the origin of the column gets lost
merge(d1, d2)
#> id a b c d
#> 1 1 2 3 2 3
# Add a suffix before merging
merge(
addSuffixToColumns(d1, ".first", except = "id"),
addSuffixToColumns(d2, ".second", except = "id"),
by = "id"
)
#> id a.first b.first c.second d.second
#> 1 1 2 3 2 3