-
Notifications
You must be signed in to change notification settings - Fork 7
/
jour2.Rmd
114 lines (75 loc) · 3.19 KB
/
jour2.Rmd
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
title: "Introduction à R"
author: Open Data France et datactivi.st
ratio: 16x10
output:
rmdshower::shower_presentation:
self_contained: false
katex: true
theme: ribbon
incremental: true
---
## Introduction à R, le couteau suisse de la data science
<p></p>
<p></p>
Jour 2
<p></p><p></p><p>
Joël Gombin et Samuel Goëta (datactivi.st)
</p>
<p>
Retrouvez les matériaux sur : [www.github.com/datactivist/IntroR_ODF](www.github.com/datactivist/IntroR_ODF)
</p>
<p>
Pad collaboratif : https://frama.link/formationR_pad2
</p>
# Installation de R et Rstudio
## Installation de R et Rstudio
- http://www.r-project.org / http://cran.univ-paris1.fr/
- https://www.rstudio.com/products/rstudio/download / https://www.rstudio.com/products/rstudio/download/preview
- (Usagers MacOS X : si difficulté à installer XCode => https://github.com/kennethreitz/osx-gcc-installer)
- installer le `tidyverse` : `install.packages("tidyverse")`
## Prise en main de Rstudio
- interface utilisateur
- notion de projets
## Trouver de l'aide avec R / Rstudio
- `?help`
- autocomplete
- google => stackoverflow / blogs / github / twitter ([#Rstats](https://twitter.com/search?vertical=default&q=%23rstats&src=typd)) / etc.
- ressources en ligne. Notamment : [r4ds](http://r4ds.had.co.nz/), [adv-r](http://adv-r.had.co.nz/), [R in action](https://www.manning.com/books/r-in-action-second-edition), [Intro à R](https://github.com/juba/intro-r), [analyse-R](http://larmarange.github.io/analyse-R/)...
- listes de diffusion et forums francophones : [email protected], [email protected], [email protected], http://forums.cirad.fr/logiciel-R/...
- [meetups R](http://www.meetup.com/fr-FR/rparis/)...
# Scripter, documenter, répliquer
## Mon premier script R
## Mon premier notebook R
## Mon premier document Rmarkdown
# Importer des données
## En GUI ou en CLI
- bouton "Import dataset"
- en CLI : package `readr` pour le CSV, `haven` pour SPSS / SAS / Stata, `readxl` pour le XLS(X), `rio` pour (presque) tout le reste
## Importez votre premier jeu de données !
- chargement de package : `library(readr)`
- Attention à l'assignation : `monjeudedonnees <- read_csv`
- Un exemple : [les aides perçues au titre de la PAC](https://www.data.gouv.fr/fr/datasets/aides-percues-par-les-personnes-morales-au-titre-de-la-politique-agricole-commune/)
## La notion de fonction
```{r}
sum(1, 2, 3)
a <- sum(1, 2, 3)
a
```
# Le tidyverse
## La notion de tidy data
> “Happy families are all alike; every unhappy family is unhappy in its own way.” – Leo Tolstoy
> “Tidy datasets are all alike, but every messy dataset is messy in its own way.” – Hadley Wickham
- À chaque variable sa propre colonne
- À chaque observation sa propre ligne
- À chaque valeur sa propre cellule
## La notion de tidy data
```{r, echo = FALSE, out.width='90%', fig.align='center'}
knitr::include_graphics("./img/tidy-1.png")
```
## La notion de tidy data
- Mettre chaque jeu de données dans un `tibble`
- Mettre chaque variable dans une colonne
## Un exemple de untidy data
https://www.data.gouv.fr/fr/datasets/election-presidentielle-2012-resultats-572126/
## Nettoyage et préparation de ce jeu de données