Search code examples
rdataframemultiplication

R multiply several columns of data frame with another column


I have a data frame of the following structure:

id country  year money1 money2 convert
1  country1 1991 4641   8494   3.1
2  country1 1991 2547   9568   3.1
3  country1 1992 3671   1494   3.3
4  country1 1992 8634   3524   3.3
5  country2 1993 8569   8496   1.7
6  country2 1993 9564   2469   1.7
7  country2 1994 3569   5496   1.9
8  country2 1994 5564   6469   1.9

The values of convert vary with country and time, but not with id. I would like to multiply the columns money1 and money2 with the respective value of convert in one single step and let the other columns remain untouched. So far, I had no luck.

Can someone help me with this?

Thanks!


Solution

  • Thanks to all who answered.

    The point is, this was a stupid question since I simply lost the overview in my code. This left me with the impression that the way I used to do the conversion, which is similar to the one proposed by Ananda, does not work while it actually did.

    Thanks anyway and sorry for wasting your time.

    Is it possible to delete this question and the answers since it won't help anyone?