Skip to content
Snippets Groups Projects
Commit 97eb3a7d authored by Carine Rey's avatar Carine Rey
Browse files

improve exercices

parent c802311a
Branches
No related tags found
No related merge requests found
Pipeline #450 passed
...@@ -557,7 +557,7 @@ function_name <- function(a, b){ ...@@ -557,7 +557,7 @@ function_name <- function(a, b){
**Note: ** if you don't use `return` by default the evaluation of the last line of your function body is returned. **Note: ** if you don't use `return` by default the evaluation of the last line of your function body is returned.
The function variable (here `x`) is independant of the global environment: It defines to which value the operation will be applied in the function body. **Note: ** The function variables (here `a` and `b`) are independant of the global environment: They define to which values the operation will be applied in the function body.
- The order of arguments is important - The order of arguments is important
...@@ -618,8 +618,11 @@ minus(b,a) ...@@ -618,8 +618,11 @@ minus(b,a)
- Naming variables is more explicit and bypasses the order. - Naming variables is more explicit and bypasses the order.
<div class="pencadre"> <div class="pencadre">
Predict the result of R1, R2 and R3. Predict the result of R1, R2, R3 and R4.
```R ```R
a <- 10
b <- 2
minus <- function(a, b){ minus <- function(a, b){
result_1 <- a - b result_1 <- a - b
return(result_1) return(result_1)
...@@ -632,21 +635,24 @@ R1 <- minus(a=6,b=3) ...@@ -632,21 +635,24 @@ R1 <- minus(a=6,b=3)
R2 <- minus(b=3,a=6) R2 <- minus(b=3,a=6)
#R3 #R3
a <- 10 R3 <- a
b <- 2
R3 <- minus(b=b,a=a) #R4
R4 <- minus(b=b,a=a)
``` ```
</div> </div>
<details><summary>Solution 1</summary> <details><summary>Solution 1</summary>
<p> <p>
```{r minus21, include=TRUE} ```{r minus21, include=TRUE}
a <- 10
b <- 2
minus <- function(a, b){ minus <- function(a, b){
result_1 <- a - b result_1 <- a - b
return(result_1) return(result_1)
} }
minus(a=6,b=3) R1 <- minus(a=6,b=3)
R1
``` ```
</p> </p>
</details> </details>
...@@ -655,7 +661,8 @@ minus(a=6,b=3) ...@@ -655,7 +661,8 @@ minus(a=6,b=3)
<details><summary>Solution 2</summary> <details><summary>Solution 2</summary>
<p> <p>
```{r minus22, include=TRUE} ```{r minus22, include=TRUE}
minus(b=3,a=6) R2 <- minus(b=3,a=6)
R2
``` ```
</p> </p>
</details> </details>
...@@ -664,9 +671,17 @@ minus(b=3,a=6) ...@@ -664,9 +671,17 @@ minus(b=3,a=6)
<details><summary>Solution 3</summary> <details><summary>Solution 3</summary>
<p> <p>
```{r minus23, include=TRUE} ```{r minus23, include=TRUE}
a <- 10 R3 <- a
b <- 2 R3
minus(b=b,a=a) ```
</p>
</details>
<details><summary>Solution 4</summary>
<p>
```{r minus24, include=TRUE}
R4 <- minus(b=b,a=a)
R4
``` ```
</p> </p>
</details> </details>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment