multiply each cell of a data.frame with it's weight

What I want to do is embarrassing simple - nevertheless I fail.

I have a data.frame with "characters" and "numerics". One of the columns of the data.frame represents the weights.

I want to multiply every cell of the data frame with the corresponding weight (if it's a numeric).

How do I do that (best without using a nested loop).

Thank you in advance!

Example:

   c1   c2   w   
l1 abc  2    1
l2 dxf  3    0.5
l3 ghi  4    1.5

should become

   c1   c2   w   
l1 abc  2    1
l2 dxf  1.5  0.5
l3 ghi  6    1.5
8
задан speendo 23 February 2011 в 13:58
поделиться