
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.
## S3 method for class 'data.frame':
Transform(.data.,.expr.,\dots)
tag=value
.data.
with all the attributes of .data.
(only the names
attribute is updated, of course).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.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