conv_ | R Documentation |
Apply a given function to specified columns in a data table
conv_(df, cols, f, ..., newcol)
df |
a data table |
cols |
a character vector of column names to which the function |
f |
a function that applies to each column. |
... |
arguments to pass to function |
newcol |
a character vector of new column names to which the output of |
This function modifies by reference. If passed a column name that does not exist in the provided data table, this will simply return the original data.table unmodified without error.
x <- data.table::data.table(x = rep("APPLE", 10), y = rep("BANANA", 10), z = rep("CHERRY", 10))
nsqipr:::conv_(x, c("x","y"), tolower)
x
x <- data.table::data.table(x = rep("APPLE", 10), y = rep("BANANA", 10), z = rep("CHERRY", 10))
nsqipr:::conv_(x, c("x","y"), tolower, newcol = c("X","Y"))
x
x <- data.table::data.table(x = rep("APPLE", 10), y = rep("BANANA", 10), z = rep("CHERRY", 10))
nsqipr:::conv_(x, "x", paste, "JUICE", sep = " ", newcol = "drink")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.