TP 1: Introduction to coding in R
a, b, d
have as value, respectively 2, 6 et 1, what are their values after the following lines of codes (this execise should be performed mentally)?
| 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 |
> fction1 <- function(eu)
{
fb <- 40.3399*eu
fb
}
What will be displayed on screen if you type the following instructions:
> fction1(100)
> fction1(200000)
> fction1(fction1(1))
> fction2 <- function(a,b)
{
a <- a + b
a + b
}
What will be displayed on screen if you type the following instructions:
> b <- 8
> a <- 13
> fction2(b,a)
> a
> 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)
> 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
What would be displayed on screen if you type the following lines of code (this execise should be performed mentally):
> 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)]
Example
DAT: 9 6 8 2
POS: 2 4 3 1
returns
.