I have a data set with around 400 observations (rows). For each row I need to find the root of a function such as: f(x)= variable_1 - variable_2 + x.
For finding the root I want to use the function uniroot.all(f,interval)
from the rootSolve package.
My question is, how do I do this for every row. Should I use a loop or would "apply" be more suitable to do this?
With "apply" I tried the follwing code, however I always get an error message.
> library(rootSolve)
> df<-as.data.frame(matrix(1:6,ncol=2))
> df
V1 V2
1 1 4
2 2 5
3 3 6
> apply(df,1,uniroot.all(fun<- function(x) df$V1-df$V2 + x, interval=c(0,100)))
Thanks a lot!