transform
Transform an Object to a Data Frame Object

Description

Transform an object to a data frame with specified input value.

Usage

transform(`_data`, ...)
transform.default(`_data`, ...)
transform.data.frame(`_data`, ...)

Arguments

`_data` the object to be transformed.
... other arguments to pass in. Should have the format tag = expression.

Details

transform is generic and has only one valid method for a data frame class. The default method is a wrapper to coerce an object to a data frame, and to call transform.data.frame method as necessary.
The ... arguments are evaluated first, matching their names to the columns names of `_data`. Matched columns are updated with the corresponding new value. For each argument that does not match, a new column is added to the data frame. See the example for details.
Value
a modified data frame.
See Also
data.frame, match
Examples
# Get a small subset of the "air" data frame
d <- Sdatasets::air[1:10, 1:4]

# Update the "temperature" column with degree Celsius, and # divided "radiation" by 10. transform(d, temperature=(temperature-32)*5/9, radiation=radiation/10.0)

# Add a new column "ctemp" with degree Celsius. transform(d, ctemp = (temperature-32)*5/9)

# Adapt to vector, transform.default is used first. transform(d$temperature, ctemp = (d$temperature-32)*5/9)

y <- 1:12 transform(y, SIN = sin(y), COS = cos(y)) # Almost similar to: data.frame(y, SIN = sin(y), COS = cos(y)) # except for difference of the first column name.

Package base version 6.1.1-7
Package Index