-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorrections_exercices_Cours1.R
89 lines (64 loc) · 3.05 KB
/
Corrections_exercices_Cours1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
##
# Gaëlle LELANDAIS <[email protected]>
##
#---------------------------------------------------------------------------
# Exercice 1
#---------------------------------------------------------------------------
vec1 = 1:12
vec1 = c(vec1, c(16, 17, 18))
print(vec1)
#---------------------------------------------------------------------------
# Exercice 2
#---------------------------------------------------------------------------
vec2 = c(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5)
vec2 = seq(0, 5, by = 0.5)
print(vec2)
#---------------------------------------------------------------------------
# Exercice 3
#---------------------------------------------------------------------------
print(4850/26)
# seulement deux ou trois décimales
print(round(4850/26, 2))
print(round(4850/26, 3))
# autre fonctions R : ceiling(); floor(); etc.
print(ceiling(4850/26))
print(floor(4850/26))
#---------------------------------------------------------------------------
# Exercice 4
#---------------------------------------------------------------------------
print(date())
dateJour = date()
m1 = 3
m2 = "je me souviendrai longtemps de mon premier script R, le"
print(paste(m1, m2, dateJour))
#---------------------------------------------------------------------------
# Exercice 5
#---------------------------------------------------------------------------
plot(c(1,2,3), c(2,2,3))
plot(c(1,2,3), c(2,2,3), cex = 2)
plot(c(1,2,3), c(2,2,3), cex = 2, pch = 20)
plot(c(1,2,3), c(2,2,3), cex = 2, pch = 20, xlim = c(0,5), ylim = c(1,6))
plot(c(1,2,3), c(2,2,3), cex = 2, pch = 20, xlim = c(0,5), ylim = c(1,6), col = c("red", "green", "blue"))
plot(c(1,2,3), c(2,2,3), cex = 2, pch = 20, xlim = c(0,5), ylim = c(1,6), col = c("red", "green", "blue"), main = "MonGraphique", xlab = "Axe X", ylab = "Axe Y")
pdf("MonGraphique.pdf")
plot(c(1,2,3), c(2,2,3), cex = 2, pch = 20, xlim = c(0,5), ylim = c(1,6), col = c("red", "green", "blue"), main = "MonGraphique", xlab = "Axe X", ylab = "Axe Y")
dev.off()
#---------------------------------------------------------------------------
# Exercice 6
#---------------------------------------------------------------------------
hist(rnorm(100, mean = 10, sd = 5))
hist(rnorm(100, mean = 10, sd = 5), nclass = 50)
vec <- rnorm(100, mean = 10, sd = 5)
hist(vec, breaks = seq(floor(min(vec)), ceiling(max(vec)), by = 0.5))
#---------------------------------------------------------------------------
# Exercice 8
#---------------------------------------------------------------------------
sample(1:100, size = 10)
#---------------------------------------------------------------------------
# Exercice 9
#---------------------------------------------------------------------------
sample(c("pile", "face"), size = 100, rep = TRUE)
#---------------------------------------------------------------------------
# Exercice 10
#---------------------------------------------------------------------------
sample(c("pile", "face"), size = 100, rep = TRUE, prob = c(0.3, 0.7))