Thanks for the help guys! For my purpose I think that rharlow2's answer, i.e.
the `rowSums' function is the most appropriate since it also takes care of
the NAs.
Best,
Vassilis
--
View this message in context:
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] =
Hi Vassilis,
Try
test.df$y - with(test.df, x1*w + x2*(1-w))
test.df
HTH,
Jorge
On Thu, Jan 6, 2011 at 8:33 AM, Vassilis wrote:
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
Em 6/1/2011 11:33, Vassilis escreveu:
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]
4 matches
Mail list logo