Learn R Programming

memisc (version 0.11-9)

Transform: Extended data frame transformation

Description

Transform is a variant of transform that preserves the attributes of the transformed data frame and allows for some preliminary computations, which can be used in variable transformations.

Note that this function is redundant since the introduction of within in R 2.6.

Usage

## S3 method for class 'data.frame':
Transform(.data.,.expr.,\dots)

Arguments

.data.
The object to be transformed
.expr.
an expression or closure (a series of expression inside curly braces).
...
Further arguments of the form tag=value

Value

  • The modified value of .data. with all the attributes of .data. (only the names attribute is updated, of course).

Details

Transform is a slightly extended version of transform. Thus it only does useful things with data frames. If an expression is given as second argument (.expr.) then it is evaluated with .data. as environment (that is, the variables inside this data frame can be accessed directly in the expression). If this expression returns a list with named elements, these elements can be accessed in subsequent tag-value assignments.

Examples

Run this code
berkeley <- aggregate(wtable(Admit,Freq)~.,data=UCBAdmissions)

Transform(berkeley,
  list(total=sum(Admitted) + sum(Rejected)),
  Admitted.p = Admitted/total,
  Rejected.p = Rejected/total)

Transform(berkeley,
  { total <- sum(Admitted) + sum(Rejected)
    list(total=total)
  },
  Admitted.p = Admitted/total,
  Rejected.p = Rejected/total)

Run the code above in your browser using DataLab