[R] Adding a calculated variable to a data frame

About this list Date view Thread view Subject view Author view Attachment view

From: Andrew Perrin (clists@perrin.socsci.unc.edu)
Date: Wed 25 Jun 2003 - 01:19:19 EST


Message-id: <Pine.LNX.4.53.0306241115010.10465@perrin.socsci.unc.edu>

Is there a shortcut way to add a calculated variable to a data frame? For
example, I have a data frame with variables first.conv, first.sub, and
first.agg. Each cell is -1, 0, or 1. I'd like to generate variables:

rwa.sum : sum(first.agg,first.sub,first.conv)
rwa.psum : total number (0-3) of vars == 1
rwa.asum : total number (0-3) of vars == -1
rwa.val : sum(abs(first.agg,first.sub,first.conv))

The only way I can think of to do this is to create a separate data.frame
to hold the calculated values, then use cbind() to paste the two together.
Am I missing an easier option?

Thanks.

----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:12:08 EST