search for: rharlow2

Displaying 1 result from an estimated 1 matches for "rharlow2".

Did you mean: harlow
2011 Jan 06
3
weighed mean of a data frame row-by-row
Dear list, This must be an easy one. I have a data frame like this one: test.df <- data.frame(x1=c(2,3,5), x2=c(5, 3, 4), w=c(0.8, 0.3, 0.5)) and I want to construct a weighted mean of the first two columns using the third column for weighting; i.e. y[1] = x1[1]*w[1] + x2[1]*(1-w[1]) y[2] = ... One way to do this is to use a loop like test.df$y <-numeric(3) with(test.df, for(i in