I have a two column dataframe in R and i want to add a third column with values that are a function of the first two.
As long as the function is a simple mathematical formula no problem
data$c <- data$a*15 - 10 + data$b*0.5
But my function is non continous and contains conditionals, i would like to do:
foo <- function(x,y){if (x<2) {return(0)} else {....}
and
data$c <- foo(data$a, data$b)
But this gets me errors. What am i missing?
I have a two column dataframe in R and i want to add a
Share
1 Answer