## ----setup, echo = FALSE------------------------------------------------------ knitr::opts_chunk$set( comment = "#", collapse = TRUE, warning = FALSE, message = FALSE, fig.width=5, fig.height=5, fig.retina=3, fig.align = 'center' ) options(repos=structure(c(CRAN="http://cran.r-project.org"))) ## ----echo = FALSE, results = "asis"------------------------------------------- qcbsRworkshops::get_badges(1, style = "for-the-badge", clip = FALSE, lang = "fr") ## ---- echo = FALSE------------------------------------------------------------ grViz(" digraph { node [shape = oval, fillcolor = PaleTurquoise] Données; Graphiques; Tableaux; Statistiques node [shape = box] Sigmaplot; Excel; SAS ##add arrows edge [arrowhead = none] Données -> Sigmaplot; Données -> Excel; Données -> SAS; edge [arrowhead = normal] Sigmaplot -> Graphiques; Excel -> Tableaux; SAS -> Statistiques; }") ## ---- echo = FALSE------------------------------------------------------------ grViz(" digraph { node [shape = oval, fillcolor = PaleTurquoise] Données; Graphiques; Tableaux; Statistiques node [shape = box] R ##add arrows edge [arrowhead = none] Données -> R; edge [arrowhead = normal] R -> Graphiques; R -> Tableaux; R -> Statistiques; }") ## ---- include = FALSE--------------------------------------------------------- sortie <- "Ceci est la sortie" ## ----------------------------------------------------------------------------- sortie ## ----------------------------------------------------------------------------- sortie ## ----------------------------------------------------------------------------- sortie ## ---- echo = FALSE------------------------------------------------------------ c(1:40) ## ----------------------------------------------------------------------------- 1 + 1 10 - 1 ## ----------------------------------------------------------------------------- 2 * 2 8 / 2 ## ----------------------------------------------------------------------------- 2^3 ## ----------------------------------------------------------------------------- 2 + 16 * 24 - 56 ## ----------------------------------------------------------------------------- 2 + 16 * 24 - 56 / (2 + 1) - 457 ## ----echo = F----------------------------------------------------------------- radius <- 1 theta <- seq(0, 2 * pi, length = 200) plot(c(-1, 1), c(-1, 1), type = "n", ann = F, axes = F, asp = 1) lines(x = radius * cos(theta), y = radius * sin(theta)) arrows(0, 0, x1 = 1, length = 0) text(.5, .1, "rayon = 5 cm", cex = 1) ## ----------------------------------------------------------------------------- 3.1416 * 5^2 ## ----------------------------------------------------------------------------- pi * 5^2 ## ---- eval = FALSE------------------------------------------------------------ ## nom_objet <- valeurs ## ----------------------------------------------------------------------------- moy_x <- (2 + 6) / 2 moy_x ## ----------------------------------------------------------------------------- valeur_euler <- 1 + 1.718282 valeur_euler ## ---- eval = FALSE------------------------------------------------------------ ## Error: unexpected symbol in "[nom de votre objet]" ## ---- eval = FALSE------------------------------------------------------------ ## vecteur <- c(valeur1, valeur2, ...) ## ----------------------------------------------------------------------------- num_vecteur <- c(1, 4, 3, 98, 32, -76, -4) num_vecteur ## ----------------------------------------------------------------------------- car_vecteur <- c("bleu", "rouge", "vert") car_vecteur ## ----------------------------------------------------------------------------- bool_vecteur <- c(TRUE, TRUE, FALSE) # ou c(T, T, F) bool_vecteur ## ----------------------------------------------------------------------------- impair <- c(1, 3, 5, 7, 9) ## ----------------------------------------------------------------------------- dput(impair) ## ----------------------------------------------------------------------------- x <- c(1:5) y <- 6 ## ----------------------------------------------------------------------------- x + y x * y ## ----------------------------------------------------------------------------- site_id <- c("A1.01", "A1.02", "B1.01", "B1.02") pH_sol <- c(5.6, 7.3, 4.1, 6.0) num_sp <- c(17, 23, 15, 7) traitement <- c("Fert", "Fert", "Non_fert", "Non_fert") ## ----------------------------------------------------------------------------- mon_df <- data.frame(site_id, pH_sol, num_sp, traitement) mon_df ## ----comment=NA, eval = FALSE------------------------------------------------- dput(mon_df) ## ----eval = FALSE------------------------------------------------------------- ## structure(list(site_id = c("A1.01", "A1.02", "B1.01", "B1.02" ## ), pH_sol = c(5.6, 7.3, 4.1, 6), num_sp = c(17, 23, 15, 7), traitement = c("Fert", ## "Fert", "Non_fert", "Non_fert")), class = "data.frame", row.names = c(NA, -4L)) ## ----------------------------------------------------------------------------- structure(list(site_id = c("A1.01", "A1.02", "B1.01", "B1.02" ), pH_sol = c(5.6, 7.3, 4.1, 6), num_sp = c(17, 23, 15, 7), traitement = c("Fert", "Fert", "Non_fert", "Non_fert")), class = "data.frame", row.names = c(NA, -4L)) ## ----------------------------------------------------------------------------- impair[2] ## ----------------------------------------------------------------------------- impair[c(2, 4)] ## ----------------------------------------------------------------------------- impair[-c(1, 2)] ## ----------------------------------------------------------------------------- impair[c(1, 6)] ## ----------------------------------------------------------------------------- impair[impair > 4] ## ----------------------------------------------------------------------------- car_vecteur car_vecteur[car_vecteur == "bleu"] ## ----------------------------------------------------------------------------- num_vecteur[4] ## ----------------------------------------------------------------------------- num_vecteur[c(1, 3)] ## ----------------------------------------------------------------------------- num_vecteur[c(-2, -4)] ## ---- eval = FALSE------------------------------------------------------------ ## car_vecteur == "bleu" ## ## car_vecteur[car_vecteur == "bleu"] ## ----------------------------------------------------------------------------- car_vecteur == "bleu" ## ----------------------------------------------------------------------------- car_vecteur[car_vecteur == "bleu"] ## ----------------------------------------------------------------------------- mon_df$num_sp * num_vecteur[c(1:4)] # ou encore mon_df[, 3] * num_vecteur[c(1:4)] ## ----------------------------------------------------------------------------- (mon_df$num_sp * num_vecteur[c(1:4)]) > 25 ## ---- eval = FALSE------------------------------------------------------------ ## nom_fonction(argument1, argument2) ## ----------------------------------------------------------------------------- a <- 3 b <- 5 sum(a, b) ## ----------------------------------------------------------------------------- a <- c(1:5) b <- 2 resultat_add <- a + b resultat_sum <- sum(a, b) ## ----------------------------------------------------------------------------- resultat_add resultat_sum sum(resultat_sum, 5) ## ---- eval = FALSE------------------------------------------------------------ ## a <- 1:100 ## b <- a^2 ## plot(a, b, type = "l") ## plot(b, a, type = "l") ## plot(x = a, y = b, type = "l") ## plot(y = b, x = a, type = "l") ## ---- echo = F---------------------------------------------------------------- a <- 1:100 b <- a^2 par(mfrow = c(2, 2),mar=c(4, 4, 1, 1)) plot(a, b, type = "l") plot(b, a, type = "l") plot(x = a, y = b, type = "l") plot(y = b, x = a, type = "l") ## ----eval=F------------------------------------------------------------------- ## plot(a, b, type = "l") ## ---- echo = FALSE, fig.width=3.6, fig.height=3.6----------------------------- par(mar=c(4, 4, 1, 1)) plot(a, b, type = "l") ## ----eval=F------------------------------------------------------------------- ## plot(b, a, type = "l") ## ---- echo = FALSE, fig.width=3.6, fig.height=3.6----------------------------- par(mar=c(4, 4, 1, 1)) plot(b, a, type = "l") ## ----eval=F------------------------------------------------------------------- ## plot(x = a, y = b, type = "l") ## ---- echo = FALSE, fig.width=3.6, fig.height=3.6----------------------------- par(mar=c(4, 4, 1, 1)) plot(x = a, y = b, type = "l") ## ----eval=F------------------------------------------------------------------- ## plot(y = b, x = a, type = "l") ## ---- echo = FALSE, fig.width=3.6, fig.height=3.6----------------------------- par(mar=c(4, 4, 1, 1)) plot(y = b, x = a, type = "l") ## ---- eval = FALSE------------------------------------------------------------ ## install.packages("ggplot2") ## ---- eval = FALSE------------------------------------------------------------ ## Installing package into '/home/labo/R/x86_64-redhat-linux-gnu-library/3.3' ## (as 'lib' is unspecified) ## ---- eval = FALSE------------------------------------------------------------ ## qplot(1:10, 1:10) ## ---- eval = FALSE------------------------------------------------------------ ## ## Error: could not find function "qplot" ## ---- fig.width=4, fig.height=4----------------------------------------------- library(ggplot2) qplot(1:10, 1:10) ## ---- eval = FALSE------------------------------------------------------------ ## ??sequence ## ---- eval = FALSE------------------------------------------------------------ ## ?seq ## ----class="fragment"--------------------------------------------------------- seq(from = 0, to = 10, by = 2) ## ----class="fragment"--------------------------------------------------------- seq(0, 10, 2) ## ----class="fragment"--------------------------------------------------------- nombres <- c(2, 4, 22, 6, 26) sort(nombres, decreasing = T)