Here, my main question is that my new variable would kept being named "x" instead of my own choice "newvar_test". I want a new variable that I name it myself in the () by using the old variable. This is then a new column named "newvar_test" in mydata. I understood I can use return but either didn't really work out.
fun1<- function(x, y) {
mutate(mydata, x =
ifelse(y == 10, 0,
ifelse(y == 1, 0.5/7,
ifelse(y == 2, 1/7,
ifelse(y == 3, 3/7,
ifelse(y == 4, 5.5/7,
ifelse(y == 5, 1,
ifelse(y == 6, 2.5,
ifelse(y== 7, 4.5,
6)))))))))
}
mydata <- fun1(newvar_test, oldvar)