View source: R/update_columns.r
update_columns | R Documentation |
Quickly update selected variables using column names or positions.
update_columns(data, ind, what)
data |
input data |
ind |
a vector of either names or column positions of the variables to be dropped. |
what |
either a function or a non-empty character string naming the function to be called. See do.call. |
This function updates data.table object directly. Otherwise, output data will be returned matching input object class.
str(update_columns(iris, 1L, as.factor))
str(update_columns(iris, c("Sepal.Width", "Petal.Length"), "as.integer"))
## Apply log transformation to all columns
summary(airquality)
summary(update_columns(airquality, names(airquality), log))
## Force set factor to numeric
df <- data.frame("a" = as.factor(sample.int(10L)))
str(df)
str(update_columns(df, "a", function(x) as.numeric(levels(x))[x]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.