TP 1: Introduction au language R
a, b, d
contiennent respectivement les nombres 2, 6 et 1, quelles sont
leurs valeurs après l'exécution de chacune des suites d'assignations ci-dessous ?
| a) | > a <- b |
d) | > d <- a |
|
> d <- b |
> a <- b |
|||
> b <- d |
||||
| b) | > a <- a + 1 |
e) | > b <- -a |
|
> b <- d + 1 |
> b <- 2 * b |
|||
> d <- 2 * d |
> a <- b |
|||
| c) | > a <- b |
f) | > a <- a * a |
|
> d <- a |
> a <- a * a |
> fonction1 <- function(eu)
{
fb <- 40.3399*eu
fb
}
Que s'affiche-t-il lorsqu'on écrit les lignes suivantes:
> fonction1(100)
> fonction1(200000)
> fonction1(fonction1(1))
Quel autre nom pourriez-vous donner à
?
> fonction2 <- function(a,b)
{
a <- a + b
a + b
}
Que s'affiche-t-il lorsqu'on écrit les lignes suivantes:
> b <- 8
> a <- 13
> fonction2(b,a)
> a
Quel autre nom pourriez-vous donner à
?
> weight <- c(60, 72, 57, 90, 95, 72) > height <- c(1.75, 1.80, 1.65, 1.90, 1.74, 1.91) > bmi(weight,height) # cf exercice bmi de la section précédente
> a <- c(TRUE,FALSE,FALSE,TRUE) > b <- c(FALSE,FALSE,TRUE,TRUE) > b|a > a&!b
> e <- c(1,2,3,5,8,13,21,34,55)
> f <- c(4,6,7,9)
> g <- rep("hello",10)
> h <- 50:60
Que s'affiche t'il après chacune de ces lignes?
> e[5] > e[6:9] > h[f[1:3]] > e[f-2] > g[e[f-3]] > c(e,f) > f[c(TRUE,FALSE,TRUE,FALSE)] > f > 7 > f[f > 6] > f[-2] > h[-c(4,6)]
Exemple (
)
DON: 9 6 8 2
POS: 2 4 3 1
donne
.