## # Gaëlle LELANDAIS ## # Sauf mention contraire, ce contenu est mis à disposition selon les # termes de la licence Creative Commons Attribution - Partage dans les mêmes # conditions 4.0 International (CC BY-SA 4.0) ## #--------------------------------------------------------------------------- # 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)) # autres fonctions R : ceiling(); floor(); etc. print(ceiling(4850/26)) print(floor(4850/26)) #--------------------------------------------------------------------------- # Exercice 4 #--------------------------------------------------------------------------- print(date()) dateJour <- date() m1 <- 3 m2 <- "aujourd'hui nous sommes 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 7 #--------------------------------------------------------------------------- sample(1:100, size = 10) #--------------------------------------------------------------------------- # Exercice 8 #--------------------------------------------------------------------------- sample(c("pile", "face"), size = 100, rep = TRUE) #--------------------------------------------------------------------------- # Exercice 9 #--------------------------------------------------------------------------- sample(c("pile", "face"), size = 100, rep = TRUE, prob = c(0.3, 0.7))