Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
a3ae0c888bdf60959264517358bb4f12
mooc-rr
Commits
9e23a3c7
Commit
9e23a3c7
authored
Nov 09, 2024
by
Jade Bolaty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
résultats exo2 orgmode R
parent
af2ef8a4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
149 additions
and
0 deletions
+149
-0
exercice_R_fr.org
module3/exo2/exercice_R_fr.org
+149
-0
No files found.
module3/exo2/exercice_R_fr.org
View file @
9e23a3c7
...
@@ -82,3 +82,152 @@ faisant ~<r~ ou ~<R~ suivi de ~Tab~).
...
@@ -82,3 +82,152 @@ faisant ~<r~ ou ~<R~ suivi de ~Tab~).
Maintenant, à vous de jouer! Vous pouvez effacer toutes ces
Maintenant, à vous de jouer! Vous pouvez effacer toutes ces
informations et les remplacer par votre document computationnel.
informations et les remplacer par votre document computationnel.
* Exo
#+begin_src R :results output :session *R* :exports both
library(parsedate)
options(OutDec=",")
options(width=150)
#+end_src
#+RESULTS:
#+begin_src R :results output :session *R* :exports both
data = read.csv('C:/Users/Jade/mooc-rr/module3/exo2/inc-7-PAY.csv', skip=1)
head(data)
tail(data)
#+end_src
#+RESULTS:
#+begin_example
week indicator inc inc_low inc_up inc100 inc100_low inc100_up geo_insee geo_name
1 202444 7 2354 489 4219 4 1 7 FR France
2 202443 7 2130 625 3635 3 1 5 FR France
3 202442 7 2621 1246 3996 4 2 6 FR France
4 202441 7 2035 381 3689 3 1 5 FR France
5 202440 7 2125 725 3525 3 1 5 FR France
6 202439 7 2898 1333 4463 4 2 6 FR France
week indicator inc inc_low inc_up inc100 inc100_low inc100_up geo_insee geo_name
1765 199102 7 16277 11046 21508 29 20 38 FR France
1766 199101 7 15565 10271 20859 27 18 36 FR France
1767 199052 7 19375 13295 25455 34 23 45 FR France
1768 199051 7 19080 13807 24353 34 25 43 FR France
1769 199050 7 11079 6660 15498 20 12 28 FR France
1770 199049 7 1143 0 2610 2 0 5 FR France
#+end_example
#+begin_src R :results output :session *R* :exports both
na_records = apply(data, 1, function(x) any(is.na(x)))
data[na_records,]
#+end_src
#+RESULTS:
: [1] week indicator inc inc_low inc_up inc100 inc100_low inc100_up geo_insee geo_name
: <0 lignes> (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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment