7/12/2023 0 Comments Create your own r package![]() ![]() Here, I’ve created a new variable, y, to store the x + 3 value. Later, when you put your function to use, you’ll have to specify values for the arguments, like I did with the 5 in add_three(5).Ĭurly brackets: come after function(argument) and need to bracket the actual function code that you’re writing.īody of the function: this is the code in the function between the curly brackets that executes the task that you want. If you want to have multiple arguments, it would look something like this: function(arg1, arg2, arg3. It doesn’t matter what we name our arguments within the parentheses (I named mine x), as long as we use the same names in the body of the function. Within the parentheses, we can specify the number of arguments that we want our function to have. “function” and arguments ( function(x)): we tell R that we want to create a function using function(). As when we create any variables or objects in R, we use the arrow <- to assign this name to our function. It should be something pretty short and easy to remember, like so many of the common functions we use (e.g., mean, plot, select). Function name ( add_three): this is just the name that you want to call your function.
0 Comments
Leave a Reply. |