Uses the function utils_clean_names()
to simplify and normalize messy column names in a time series list.
The cleanup operations are applied in the following order:
Remove leading and trailing whitespaces.
Generates syntactically valid names with
base::make.names()
.Replaces dots and spaces with the
separator
.Coerces names to lowercase.
If
capitalize_first = TRUE
, the first letter is capitalized.If
capitalize_all = TRUE
, all letters are capitalized.If argument
length
is provided,base::abbreviate()
is used to abbreviate the new column names.If
suffix
is provided, it is added at the end of the column name using the separator.If
prefix
is provided, it is added at the beginning of the column name using the separator.
Usage
tsl_colnames_clean(
tsl = NULL,
lowercase = FALSE,
separator = "_",
capitalize_first = FALSE,
capitalize_all = FALSE,
length = NULL,
suffix = NULL,
prefix = NULL
)
Arguments
- tsl
(required, list) Time series list. Default: NULL
- lowercase
(optional, logical) If TRUE, all names are coerced to lowercase. Default: FALSE
- separator
(optional, character string) Separator when replacing spaces and dots. Also used to separate
suffix
andprefix
from the main word. Default: "_".- capitalize_first
(optional, logical) Indicates whether to capitalize the first letter of each name Default: FALSE.
- capitalize_all
(optional, logical) Indicates whether to capitalize all letters of each name Default: FALSE.
- length
(optional, integer) Minimum length of abbreviated names. Names are abbreviated via
abbreviate()
. Default: NULL.- suffix
(optional, character string) String to append to the column names. Default: NULL.
- prefix
(optional, character string) String to prepend to the column names. Default: NULL.
See also
Other tsl_management:
tsl_burst()
,
tsl_colnames_get()
,
tsl_colnames_prefix()
,
tsl_colnames_set()
,
tsl_colnames_suffix()
,
tsl_count_NA()
,
tsl_diagnose()
,
tsl_handle_NA()
,
tsl_join()
,
tsl_names_clean()
,
tsl_names_get()
,
tsl_names_set()
,
tsl_names_test()
,
tsl_ncol()
,
tsl_nrow()
,
tsl_repair()
,
tsl_subset()
,
tsl_time()
,
tsl_time_class_set()
,
tsl_to_df()
Examples
#generate example data
tsl <- tsl_simulate(cols = 3)
#list all column names
tsl_colnames_get(
tsl = tsl
)
#> $A
#> [1] "a" "b" "c"
#>
#> $B
#> [1] "a" "b" "c"
#>
#rename columns
tsl <- tsl_colnames_set(
tsl = tsl,
names = c(
"New name 1",
"new Name 2",
"NEW NAME 3"
)
)
#check new names
tsl_colnames_get(
tsl = tsl,
names = "all"
)
#> $A
#> [1] "New name 1" "new Name 2" "NEW NAME 3"
#>
#> $B
#> [1] "New name 1" "new Name 2" "NEW NAME 3"
#>
#clean names
tsl <- tsl_colnames_clean(
tsl = tsl
)
tsl_colnames_get(
tsl = tsl
)
#> $A
#> [1] "New_name_1" "new_Name_2" "NEW_NAME_3"
#>
#> $B
#> [1] "New_name_1" "new_Name_2" "NEW_NAME_3"
#>
#abbreviated
tsl <- tsl_colnames_clean(
tsl = tsl,
capitalize_first = TRUE,
length = 6,
suffix = "clean"
)
tsl_colnames_get(
tsl = tsl
)
#> $A
#> [1] "Nw_n_1_clean" "Nw_N_2_clean" "NEW_NA_clean"
#>
#> $B
#> [1] "Nw_n_1_clean" "Nw_N_2_clean" "NEW_NA_clean"
#>