transform: Transform varibles

Description Usage Arguments Details Value Author(s) Examples

View source: R/transform.R

Description

Mutate input variables using a formula.

Usage

1
2
transform(from, formula, as = NULL,
          na.remove = FALSE, logic_convert = TRUE, ...)

Arguments

from

a data.frame object with variables

formula

a formula indicating the operation to create new varibles. Look at the detail section for explanantion.

as

a character vector with names of new variables.

na.remove

a logical value indicating whether NA values should be removed.

logic_convert

logical value indicating if the new logical varaible are converted to 0 or 1

...

further arguments

Details

The formula is composed of two part:

column_names ~ trasformed_variables

the left-hand side are the names of the column to transform, and the right-hand the operations applied to the selected columns, using the I() function.

For example:

column_names1 + column_names2 ~ I(log(column_names1)) + I(column_names2/100)

the column_names1 is mutated in log(column_names1) and column_names2 is divided by 100.

If na.remove is set to TRUE, variables are mutaded, and then the observation with missing are removed.

Value

Returns the original data.frame object with mutaded varaibles.

Author(s)

Alessio Serafini

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
data("airquality")
dt <- airquality

head(transform(from = dt, Ozone ~ I(Ozone-Ozone)))
head(transform(from = dt, Ozone ~ log(Ozone)))
head(transform(from = dt, Ozone ~ I(Ozone>5)))
head(transform(from = dt, Ozone ~ I(Ozone>5), logic_convert = TRUE))


head(transform(from = dt,  ~ log()))
head(transform(from = dt, . ~ log()))
head(transform(from = dt, NULL ~ log()))

head(transform(from = dt, Ozone + Day ~ log()))
head(transform(from = dt, Ozone + Day ~ log(Ozone/100) + exp(Day)))
head(transform(from = dt, Ozone ~ log()))

head(transform(from = dt,Ozone + Wind ~ C(log(1))))
head(transform(from = dt,Ozone + Wind ~ log(Ozone) + C(10)))


head(transform(from = dt, Ozone + Wind~ C(log(Ozone))))


foo <- function(x, a = 100){return(x-x + a)}
head(transform(from = dt, Ozone + Wind ~ foo(a = 100)))
head(transform(from = dt, . ~ foo(a = 100)))

head(transform(from = dt, Ozone + Wind ~ log(log(1))))

dformula documentation built on July 2, 2020, 3:37 a.m.