简体   繁体   中英

passing and returning a variable to a function in r

I created a function and want to replace x by another variable called s and set y=3. How to do it so that the function with return s+3?

myfun <- function(x, y){ x + y }

myfun(s, 3) will give me an error that s is undefined. 

It sounds like you just want the substitute function

myfun <- function(x, y){ substitute(x + y) }
myfun(s, 3)
# s + 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM