Hi I have a simple data frame with 2 columns
scenario item ROA
0 -10 0 A 6.0
0 0 10 A 2.1
0 10 20 A 3.0
0 -30 0 B 0.5
10 0 0 B 1.0
What I need is to create a way to be able to condition the scenarios for each item (only positive or negative) and return the row where there is the max value of ROA
For example if I condition A to use only scenarios positive and B to only negative I should get
scenario item ROA
0 10 20 A 3.0
0 -30 0 B 0.5
the values on the scenario column are strings not numbers, but there is only one negative sign, so it can be checked with a condition if it contains the "-" sign.
the condition for being negative scenario is just that it has a negative char in the string, the condition for being positive is that it does not.
Here you can create some sample data
scenario <- c("0 -10 0","0 0 10","0 10 20","0 -30 0","0 -30 0")
item <- c("A","A","A","B","B")
ROA <- c(6,2.1,3,0.5,1)
dfts <- data.frame(scenario=scenario, item=item, ROA=ROA )
Thanks for the help