From 9e23a3c750149ede6386335d97dcbd6beb7823a3 Mon Sep 17 00:00:00 2001 From: Jade Bolaty Date: Sat, 9 Nov 2024 10:08:53 +0100 Subject: [PATCH] =?UTF-8?q?r=C3=A9sultats=20exo2=20orgmode=20R?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module3/exo2/exercice_R_fr.org | 149 +++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/module3/exo2/exercice_R_fr.org b/module3/exo2/exercice_R_fr.org index 1bb8f61..09aec39 100644 --- a/module3/exo2/exercice_R_fr.org +++ b/module3/exo2/exercice_R_fr.org @@ -82,3 +82,152 @@ faisant ~ (ou 'row.names' de longueur nulle) + +#+begin_src R :results output :session *R* :exports both +class(data$week) +class(data$inc) +#+end_src + +#+RESULTS: +: [1] "integer" +: [1] "integer" + +#+begin_src R :results output :session *R* :exports both +convert_week = function(w) { + ws = paste(w) + iso = paste0(substring(ws,1,4), "-W", substring(ws,5,6)) + as.Date(parse_iso_8601(iso)) + } + +data$date = as.Date(convert_week(data$week)) +class(data$date) +data = data[order(data$date),] +#+end_src + +#+RESULTS: +: [1] "Date" + +#+begin_src R :results output :session *R* :exports both +all(diff(data$date) == 7) +#+end_src + +#+RESULTS: +: [1] TRUE + +#+begin_src R :results file graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R* +plot(data$date, data$inc, type="l", xlab="Date", ylab="Incidence hebdomadaire") +#+end_src + +#+RESULTS: +[[file:c:/Users/Jade/AppData/Local/Temp/babel-luSDal/figure7G7sme.png]] +#+begin_src R :results file graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R* +with(tail(data, 200), plot(date, inc, type="l", xlab="Date", ylab="Incidence hebdomadaire")) +#+end_src + +#+RESULTS: +[[file:c:/Users/Jade/AppData/Local/Temp/babel-luSDal/figureAF8kaK.png]] +#+begin_src R :results output :session *R* :exports both +pic_annuel = function(annee) { + debut = paste0(annee-1,"-09-01") + fin = paste0(annee,"-09-01") + semaines = data$date > debut & data$date <= fin + sum(data$inc[semaines], na.rm=TRUE) + } +annees <- 1992:2024 + +inc_annuelle = data.frame(annee = annees, + incidence = sapply(annees, pic_annuel)) +head(inc_annuelle) +#+end_src + +#+RESULTS: +: annee incidence +: 1 1992 834935 +: 2 1993 642921 +: 3 1994 662750 +: 4 1995 651333 +: 5 1996 564994 +: 6 1997 683577 + +#+begin_src R :results file graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R* +plot(inc_annuelle, type="p", xlab="Année", ylab="Incidence annuelle") +#+end_src + +#+RESULTS: +[[file:c:/Users/Jade/AppData/Local/Temp/babel-luSDal/figurecbYM5J.png]] +#+begin_src R :results output :session *R* :exports both +head(inc_annuelle[order(-inc_annuelle$incidence),]) +#+end_src + +#+RESULTS: +: annee incidence +: 18 2009 841233 +: 1 1992 834935 +: 19 2010 834077 +: 25 2016 779816 +: 13 2004 778914 +: 12 2003 760765 + +#+begin_src R :results file graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R* +hist(inc_annuelle$incidence, breaks=10, xlab="Incidence annuelle", ylab="Nb d'observations", main="") +#+end_src + +#+RESULTS: +[[file:c:/Users/Jade/AppData/Local/Temp/babel-luSDal/figureuIwnf5.png]] + +#+begin_src R :results output :session *R* :exports both +head(inc_annuelle[order(inc_annuelle$incidence),]) +#+end_src + +#+RESULTS: +: annee incidence +: 29 2020 221183 +: 32 2023 365607 +: 30 2021 377933 +: 33 2024 479917 +: 11 2002 515343 +: 27 2018 539765 -- 2.18.1