Learn R Programming

DataExplorer (version 0.8.3)

update_columns: Update variable types or values

Description

Quickly update selected variables using column names or positions.

Usage

update_columns(data, ind, what)

Arguments

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.

Details

This function updates data.table object directly. Otherwise, output data will be returned matching input object class.

Examples

Run this code
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]))

Run the code above in your browser using DataLab