I have a data frame with 4 columns. I want to add a fith column with values from a function that uses the values of the row in in data frame as an input.
I have tried the following for example...
my.function <-(input1,input2,input3){
random = sample(10:200,1)
if((input1>=5) & (input2>=15) & (input3>=35)){
(input1 * input2 * input3) + random
}else{
(input1+input2+input3) + random
}
}
}
my.frame <- (1:10,11:20,21:30,31:40)
my.frame$new.col <- my.function(my.frame[,1],my.frame[,2],my.frame[,3])
...but this does not work.
What am I doing wrong?
EDIT: I have added an example for the function. It should now be reproducible.