Apply transformations to an arbitrary number of columns.
Source:R/utility-functions.R
transform_columns.Rd
This function takes a named list of purr-style lambdas where names are the names of the columns in the data frame that must be transformed. NOTE: the columns are overridden, not appended.
Details
Lambdas provided in input must be transformations, aka functions that take in input a vector and return a vector of the same length as the input.
If the input transformation list contains column names that are not present in the input data frame, they are simply ignored.
See also
Other Utilities:
as_sparse_matrix()
,
comparison_matrix()
,
enable_progress_bars()
,
export_ISA_settings()
,
generate_Vispa2_launch_AF()
,
generate_blank_association_file()
,
generate_default_folder_structure()
,
import_ISA_settings()
,
separate_quant_matrices()
Examples
df <- tibble::tribble(
~A, ~B, ~C, ~D,
1, 2, "a", "aa",
3, 4, "b", "bb",
5, 6, "c", "cc"
)
lambdas <- list(A = ~ .x + 1, B = ~ .x + 2, C = ~ stringr::str_to_upper(.x))
transform_columns(df, lambdas)
#> # A tibble: 3 × 4
#> A B C D
#> <dbl> <dbl> <chr> <chr>
#> 1 2 4 A aa
#> 2 4 6 B bb
#> 3 6 8 C cc