I have a very large dataframe...
v.l.df <- data.frame(seq(0, 10, 0.0001),seq(0, 10, 0.0001),seq(0, 10, 0.0001))
...and a function with some if statements and calculations...
a.f <- function(cell_value,action){
if(action == 1){
cell_value * 1
}
else if(action == 2){
cell_value * 5
}
}
I now want to apply this function to the first two columns of my v.l.df
row by row and build the sums of the returns. The new columns should thus contain (pseudo code):
new_col_1 new_col_2
a.f(v.l.df[1,1],1) + a.f(v.l.df[1,2],1) a.f(v.l.df[1,1],2) + a.f(v.l.df[1,2],2)
a.f(v.l.df[2,1],1) + a.f(v.l.df[2,2],1) a.f(v.l.df[2,1],2) + a.f(v.l.df[2,2],2)
...
How can this be achieved? I am struggeling with the multiple arguments when using apply and the sum of the returned values form the function.
EDIT: Changed the example function. Should now return the folowing
> a.f(2,1)
[1] 2
> a.f(2,2)
[1] 10