1 Dec 01:51 2011

### Re: how to call a function for each row

Florent D. <flodel <at> gmail.com>

2011-12-01 00:51:26 GMT

2011-12-01 00:51:26 GMT

if you want to store the result in a column of your data.frame: within(df, Y <- 6*X1+7*X2+8*X3) On Wed, Nov 30, 2011 at 9:59 AM, David L Carlson <dcarlson <at> tamu.edu> wrote: > Isn't this even easier? > >> X1 <- c(1:3) >> X2 <- c(3, 4, 6) >> X3 <- c(5, 6, 1) >> Y <- 6*X1 + 7*X2 + 8*X3 >> Y > [1] 67 88 68 > > Or if you really need a function: > >> MakeY <- function(x, y, z) 6*x + 7*y + 8*z >> MakeY(X1, X2, X3) > [1] 67 88 68 > > > ---------------------------------------------- > David L Carlson > Associate Professor of Anthropology > Texas A&M University > College Station, TX 77843-4352 > > > > -----Original Message-----(Continue reading)