I want to create a function in R, which take data as a function, do some operation on it(add some columns/Rows etc) and return it. I found usually I can not do so.
f <- function(d = cars){
d$new = ifelse(d$dist > rep(10, nrow(d)), 1, 0)
return d
}
Error: unexpected symbol in:
"d$new= ifelse(d$dist>rep(10,nrow(d)),1,0)
return d"
If I remove return d, I get only the vector, not whole data frame.
Any suggestion?