[R] calculate value in dependence of target value

David L Carlson dcarlson at tamu.edu
Mon Mar 9 16:07:37 CET 2015


It is very hard to figure out what you are trying to do. 

1. All of the VALUEs are greater than the target of 100
2. Your description of what you want does not match your example.

Perhaps VALUE should be divided by 1000 (e.g. not 10000, but 10)?
Perhaps your targets do not apply to VALUE, but to cumulative VALUE?

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352



-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Matthias Weber
Sent: Monday, March 9, 2015 7:46 AM
To: r-help at r-project.org
Subject: [R] calculate value in dependence of target value

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]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list