#### Read Microsoft Word - R notes 3 text version

How to write functions in R: For example You want to write a function to return the square of a value in R. square = function(number){ answer = number * number return(answer) } square is the name of the function. function is the R function that creates functions. number is the parameter (name of the value) passed to the square function. { delimits the beginning of the function } delimits the end of the function return is the R function that specifies what the function returns, in this example, the value of answer Thus, if you want to have the square of 5, then the syntax is: square = function(number){ answer = number * number return(answer) } square(5) For exercise: Write a function to calculate the sum of two values. Codes: add = function(value1, value2){ answer = value1 + value2 return(answer) } Thus, if you want to calculate the sum of 230 and 140, then: add = function(value1, value2){ answer = value1 + value2 return(answer) } add(230, 140)

#### Information

#### Report File (DMCA)

Our content is added by our users. **We aim to remove reported files within 1 working day.** Please use this link to notify us:

Report this file as copyright or inappropriate

1323200

### You might also be interested in

^{BETA}