[R] calculate value in dependence of target value

Matthias Weber Matthias.Weber at fntsoftware.com
Mon Mar 9 13:45:50 CET 2015


Hello together,

i have a litte problem. Maybe anyone can help me.

I have to calculate a new column in dependence of a target value.

As a example: My target value is 100.000
At the moment I have a data.frame with the following values.

     ID    VALUE
1   11    10000
2   12    50000
3   13    30000
4   14    20000

The new column ("MARGE") should be calculated with the following graduation:
Until the VALUE reach 50% of the target value (50.000) = 2%
Until the VALUE reach 75% of the target value (75.000) = 4%
Until the VALUE reach 100% of the target value (<100.000) = 8%
If the VALUE goes above 100% of the value (>100.000) = 10%

The result looks like this one:

     ID    VALUE  MARGE
1   11    10000          200      (result of 10.000 * 2%)
2   12    50000         1200     (result of 40.000 * 2% + 10.000 * 4%)
3   13    30000         1800     (result of 15.000 * 4% + 15.000 * 8%)
4   14    20000         1800     (result of 10.000 * 8% + 10.000 * 10%)

Is there anyway to calculate the column "MARGE" automatically in R?

Thanks a lot for your help.

Best regards.

Mat

________________________________
This e-mail may contain trade secrets, privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.

Diese E-Mail kann Betriebs- oder Geschaeftsgeheimnisse oder sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtuemlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfaeltigung oder Weitergabe der E-Mail ausdruecklich untersagt. Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen Dank.

	[[alternative HTML version deleted]]



More information about the R-help mailing list