Skip to content
Prev 317892 / 398503 Next

How to do a backward calculation for each record in a dataset

On 19-02-2013, at 09:55, Prakasit Singkateera <asltjoey.rsoft at gmail.com> wrote:

            
1. You don't need rootSolve. uniroot is sufficient in your case. You don't have multiple roots for each element of cost.

2. You are now storing more information than you require into the resulting dataframe. Use uniroot(?)$root to store only the root of the equation.

3. you don't need plyr. You can do it like this

mysolution <- within(mydata, 
    no.of.orders <- sapply(seq_len(length(cost)),function(k) uniroot(f.to.findroot,interval = c(0,1000),fcost=cost[k])$root )
)
# for printing the dataframe

mysolution

Berend