update_columns: Update variable types or values

Description Usage Arguments Details Examples

View source: R/update_columns.r

Description

Quickly update selected variables using column names or positions.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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]))

boxuancui/eda documentation built on Dec. 9, 2020, 11:11 p.m.