use dplyr mutate() in programming

Viewed 2655

I am trying to assign a column name to a variable using mutate.

df <-data.frame(x = sample(1:100, 50), y = rnorm(50))

new <- function(name){
     df%>%mutate(name = ifelse(x <50, "small", "big"))
}

When I run

new(name = "newVar")

it doesn't work. I know mutate_() could help but I'm struggling in using it together with ifelse.

Any help would be appreciated.

3 Answers
Related