I have a data frame in R with 3 columns in it and millions of rows:
> df
col1 col2 col3
1 one 1.1 4
2 two 1.5 1
3 three 1.7 5
. .. .. ..
I would like to do a calculation based on two of these columns. I would like to create a column that is basically something like:
if col1 == "one", then result = col2*.0.5,
else if col1 == "two, then result = col2*0.6
else if ...
but short of doing a really big for loop over all millions of rows, I can't think of a more "R" way to do this without for loops. Any suggestions?
Thanks!