Replace Column Values with Shorter Version
abbreviate_by_column.Rd
This function shortens the character column values in a data frame by removing vowels after the first character, and also provides an option to disable this vowel removal. It replaces spaces with underscores and removes characters after a slash. If no column names are provided, the function attempts to find and use the first character column in the data frame.
Arguments
- df
A data frame.
- col_names
A character vector specifying the names of the columns to be abbreviated. If NULL (default), the function attempts to use the first character column.
- remove_vowels
A logical value indicating whether to remove vowels from column values after the first character. Default is FALSE.
Examples
df <- data.frame(
col1 = c("Hutan lahan kering sekunder / bekas tebangan", "Savanna / Padang rumput"),
col2 = c("Hutan lahan kering sekunder", "Savanna"),
stringsAsFactors = FALSE
)
abbreviate_by_column(df, c("col1", "col2"), remove_vowels=TRUE)
#> col1 col2
#> 1 Htn_lhn_krng_skndr Htn_lhn_krng_skndr
#> 2 Svnn Svnn