上QQ阅读APP看书,第一时间看更新
Functions
As you grow in confidence with R, you will want to begin writing your own functions. This is achieved very simply, and in a manner quite similar to many other languages. You will no doubt want to read more about writing functions in R in more detail, but just to give you an idea, the following code is a function called the sumMultiply function that adds together x and y and multiplies the result by z:
sumMultiply <- function(x, y, z){ final = (x+y) * z return(final) }
This function can now be called using sumMultiply(2, 3, 6), which will return 2 plus 3 times 6, which gives 30.