| Transform {memisc} | R Documentation |
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.
## S3 method for class 'data.frame': Transform(.data.,.expr.,...)
.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 |
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.
The modified value of .data. with all the attributes of .data.
(only the names attribute is updated, of course).
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)