Commit be28f8aa authored by Laurence Viry's avatar Laurence Viry
Browse files

mise à jour ManipDon

parent 69d94a23
Pipeline #11196 failed with stages
in 18 seconds
......@@ -50,11 +50,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"'/Users/viryl/formation/FormationContinue/ATMO/ATMO_IntroR/notebooks'"
],
"text/latex": [
"'/Users/viryl/formation/FormationContinue/ATMO/ATMO\\_IntroR/notebooks'"
],
"text/markdown": [
"'/Users/viryl/formation/FormationContinue/ATMO/ATMO_IntroR/notebooks'"
],
"text/plain": [
"[1] \"/Users/viryl/formation/FormationContinue/ATMO/ATMO_IntroR/notebooks\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Lecture du fichier donnees.csv\n",
"getwd() # repertoire de travail\n",
......@@ -74,9 +91,46 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"'list'"
],
"text/latex": [
"'list'"
],
"text/markdown": [
"'list'"
],
"text/plain": [
"[1] \"list\""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"'data.frame'"
],
"text/latex": [
"'data.frame'"
],
"text/markdown": [
"'data.frame'"
],
"text/plain": [
"[1] \"data.frame\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# \"mode\" et \"class\" \n",
"mode(don)\n",
......@@ -102,9 +156,86 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<dl>\n",
"\t<dt>$names</dt>\n",
"\t\t<dd><ol class=list-inline>\n",
"\t<li>'taille'</li>\n",
"\t<li>'poids'</li>\n",
"\t<li>'pointure'</li>\n",
"\t<li>'sexe'</li>\n",
"</ol>\n",
"</dd>\n",
"\t<dt>$class</dt>\n",
"\t\t<dd>'data.frame'</dd>\n",
"\t<dt>$row.names</dt>\n",
"\t\t<dd><ol class=list-inline>\n",
"\t<li>'roger'</li>\n",
"\t<li>'theodule'</li>\n",
"\t<li>'nicolas'</li>\n",
"</ol>\n",
"</dd>\n",
"</dl>\n"
],
"text/latex": [
"\\begin{description}\n",
"\\item[\\$names] \\begin{enumerate*}\n",
"\\item 'taille'\n",
"\\item 'poids'\n",
"\\item 'pointure'\n",
"\\item 'sexe'\n",
"\\end{enumerate*}\n",
"\n",
"\\item[\\$class] 'data.frame'\n",
"\\item[\\$row.names] \\begin{enumerate*}\n",
"\\item 'roger'\n",
"\\item 'theodule'\n",
"\\item 'nicolas'\n",
"\\end{enumerate*}\n",
"\n",
"\\end{description}\n"
],
"text/markdown": [
"$names\n",
": 1. 'taille'\n",
"2. 'poids'\n",
"3. 'pointure'\n",
"4. 'sexe'\n",
"\n",
"\n",
"\n",
"$class\n",
": 'data.frame'\n",
"$row.names\n",
": 1. 'roger'\n",
"2. 'theodule'\n",
"3. 'nicolas'\n",
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"$names\n",
"[1] \"taille\" \"poids\" \"pointure\" \"sexe\" \n",
"\n",
"$class\n",
"[1] \"data.frame\"\n",
"\n",
"$row.names\n",
"[1] \"roger\" \"theodule\" \"nicolas\" \n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Attributs d'un data-frame\n",
"attributes(don)"
......@@ -112,9 +243,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'data.frame':\t3 obs. of 4 variables:\n",
" $ taille : num 184 176 158\n",
" $ poids : int 80 5 72\n",
" $ pointure: int 44 43 42\n",
" $ sexe : Factor w/ 1 level \"M\": 1 1 1\n"
]
}
],
"source": [
"# Afficher de manière compacte la structure d'un objet R \n",
"str(don)"
......@@ -143,9 +286,74 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ol>\n",
"\t<li><ol class=list-inline>\n",
"\t<li>'roger'</li>\n",
"\t<li>'theodule'</li>\n",
"\t<li>'nicolas'</li>\n",
"</ol>\n",
"</li>\n",
"\t<li><ol class=list-inline>\n",
"\t<li>'taille'</li>\n",
"\t<li>'poids'</li>\n",
"\t<li>'pointure'</li>\n",
"\t<li>'sexe'</li>\n",
"</ol>\n",
"</li>\n",
"</ol>\n"
],
"text/latex": [
"\\begin{enumerate}\n",
"\\item \\begin{enumerate*}\n",
"\\item 'roger'\n",
"\\item 'theodule'\n",
"\\item 'nicolas'\n",
"\\end{enumerate*}\n",
"\n",
"\\item \\begin{enumerate*}\n",
"\\item 'taille'\n",
"\\item 'poids'\n",
"\\item 'pointure'\n",
"\\item 'sexe'\n",
"\\end{enumerate*}\n",
"\n",
"\\end{enumerate}\n"
],
"text/markdown": [
"1. 1. 'roger'\n",
"2. 'theodule'\n",
"3. 'nicolas'\n",
"\n",
"\n",
"\n",
"2. 1. 'taille'\n",
"2. 'poids'\n",
"3. 'pointure'\n",
"4. 'sexe'\n",
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"[[1]]\n",
"[1] \"roger\" \"theodule\" \"nicolas\" \n",
"\n",
"[[2]]\n",
"[1] \"taille\" \"poids\" \"pointure\" \"sexe\" \n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Nom des lignes(1.) et des colonnes(2.)\n",
"dimnames(don)"
......@@ -162,9 +370,62 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" taille poids pointure sexe \n",
" Min. :100.0 Min. :15 Min. :22.00 F :2 \n",
" 1st Qu.:110.0 1st Qu.:30 1st Qu.:30.50 M :3 \n",
" Median :160.0 Median :72 Median :40.00 NA's:1 \n",
" Mean :145.9 Mean :55 Mean :36.17 \n",
" 3rd Qu.:175.5 3rd Qu.:78 3rd Qu.:42.75 \n",
" Max. :184.0 Max. :80 Max. :44.00 \n",
" NA's :1 NA's :1 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"&lt;NA&gt;"
],
"text/latex": [
"<NA>"
],
"text/markdown": [
"&lt;NA&gt;"
],
"text/plain": [
"[1] NA"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"55"
],
"text/latex": [
"55"
],
"text/markdown": [
"55"
],
"text/plain": [
"[1] 55"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"don2 <- read.csv(file = \"data/don2.csv\",header=TRUE,sep=\";\",dec=\",\",row.names=1,na.strings=\"***\")\n",
"summary(don2)\n",
......@@ -189,6 +450,17 @@
"summary(df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### On peut spécifier le mode des variables\n",
"\n",
"Utiliser l'option **colClasses**\n",
"\n",
"**colClasses=c(\"character\",rep(\"numeric\",5))** indique que la première variable est de mode \"character\" et les 5 suivantes sont numériques."
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -197,7 +469,7 @@
"\n",
"La fonction **scan** est plus flexible que **read.table**.\n",
"\n",
"* Une différence est qu'il est possible de spécifier le mode des variables:"
"* Il est possible de spécifier le mode des variables:"
]
},
{
......@@ -245,10 +517,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# Importer le package\n",
......@@ -271,9 +541,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# \"class\" de l'objet df\n",
......@@ -282,9 +550,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" Sepal.Length Sepal.Width Petal.Length Petal.Width \n",
" Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 \n",
" 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 \n",
" Median :5.800 Median :3.000 Median :4.350 Median :1.300 \n",
" Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 \n",
" 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 \n",
" Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 \n",
" Species \n",
" Length:150 \n",
" Class :character \n",
" Mode :character \n",
" \n",
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"summary(df)"
]
......@@ -300,9 +591,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ol class=list-inline>\n",
"\t<li>'iris'</li>\n",
"\t<li>'mtcars'</li>\n",
"\t<li>'chickwts'</li>\n",
"\t<li>'quakes'</li>\n",
"</ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 'iris'\n",
"\\item 'mtcars'\n",
"\\item 'chickwts'\n",
"\\item 'quakes'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 'iris'\n",
"2. 'mtcars'\n",
"3. 'chickwts'\n",
"4. 'quakes'\n",
"\n",
"\n"
],
"text/plain": [
"[1] \"iris\" \"mtcars\" \"chickwts\" \"quakes\" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Liste des feuilles du classeur \"datasets.xls\".\n",
"excel_sheets(datasets)"
......@@ -310,12 +635,72 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<ol class=list-inline>\n",
"\t<li>'tbl_df'</li>\n",
"\t<li>'tbl'</li>\n",
"\t<li>'data.frame'</li>\n",
"</ol>\n"
],
"text/latex": [
"\\begin{enumerate*}\n",
"\\item 'tbl\\_df'\n",
"\\item 'tbl'\n",
"\\item 'data.frame'\n",
"\\end{enumerate*}\n"
],
"text/markdown": [
"1. 'tbl_df'\n",
"2. 'tbl'\n",
"3. 'data.frame'\n",
"\n",
"\n"
],
"text/plain": [
"[1] \"tbl_df\" \"tbl\" \"data.frame\""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
" mpg cyl disp hp \n",
" Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0 \n",
" 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5 \n",
" Median :19.20 Median :6.000 Median :196.3 Median :123.0 \n",
" Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7 \n",
" 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0 \n",
" Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0 \n",
" drat wt qsec vs \n",
" Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000 \n",
" 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000 \n",
" Median :3.695 Median :3.325 Median :17.71 Median :0.0000 \n",
" Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375 \n",
" 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000 \n",
" Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000 \n",
" am gear carb \n",
" Min. :0.0000 Min. :3.000 Min. :1.000 \n",
" 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000 \n",
" Median :0.0000 Median :4.000 Median :2.000 \n",
" Mean :0.4062 Mean :3.688 Mean :2.812 \n",
" 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000 \n",
" Max. :1.0000 Max. :5.000 Max. :8.000 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Lecture d'une des feuilles\n",
"df <- read_excel(datasets,sheet = \"iris\")\n",
"df <- read_excel(datasets,sheet = \"mtcars\")\n",
"class(df)\n",
"summary(df)"
]
......@@ -372,9 +757,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"read_excel(datasets,sheet = \"iris\",range = cell_cols(\"B:D\"))"
......@@ -390,9 +773,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"read_excel(datasets,sheet = \"iris\",range = cell_cols(2:4))"
......@@ -407,11 +788,57 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"read_excel(datasets,sheet = \"mtcars\",range = \"B1:D5\")"
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<thead><tr><th scope=col>Sepal.Width</th><th scope=col>Petal.Length</th><th scope=col>Petal.Width</th></tr></thead>\n",
"<tbody>\n",
"\t<tr><td>3.5</td><td>1.4</td><td>0.2</td></tr>\n",
"\t<tr><td>3.0</td><td>1.4</td><td>0.2</td></tr>\n",
"\t<tr><td>3.2</td><td>1.3</td><td>0.2</td></tr>\n",
"\t<tr><td>3.1</td><td>1.5</td><td>0.2</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"\\begin{tabular}{r|lll}\n",
" Sepal.Width & Petal.Length & Petal.Width\\\\\n",
"\\hline\n",
"\t 3.5 & 1.4 & 0.2\\\\\n",
"\t 3.0 & 1.4 & 0.2\\\\\n",
"\t 3.2 & 1.3 & 0.2\\\\\n",
"\t 3.1 & 1.5 & 0.2\\\\\n",
"\\end{tabular}\n"
],
"text/markdown": [
"\n",
"Sepal.Width | Petal.Length | Petal.Width | \n",
"|---|---|---|---|\n",
"| 3.5 | 1.4 | 0.2 | \n",
"| 3.0 | 1.4 | 0.2 | \n",
"| 3.2 | 1.3 | 0.2 | \n",
"| 3.1 | 1.5 | 0.2 | \n",
"\n",
"\n"
],
"text/plain": [
" Sepal.Width Petal.Length Petal.Width\n",
"1 3.5 1.4 0.2 \n",
"2 3.0 1.4 0.2 \n",
"3 3.2 1.3 0.2 \n",
"4 3.1 1.5 0.2 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"read_excel(datasets,sheet = \"iris\",range = \"B1:D5\")"
]
},
{
......@@ -423,11 +850,57 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"read_excel(datasets,range =\"mtcars!B1:D5\")"
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
"<thead><tr><th scope=col>Sepal.Width</th><th scope=col>Petal.Length</th><th scope=col>Petal.Width</th></tr></thead>\n",
"<tbody>\n",
"\t<tr><td>3.5</td><td>1.4</td><td>0.2</td></tr>\n",
"\t<tr><td>3.0</td><td>1.4</td><td>0.2</td></tr>\n",
"\t<tr><td>3.2</td><td>1.3</td><td>0.2</td></tr>\n",
"\t<tr><td>3.1</td><td>1.5</td><td>0.2</td></tr>\n",
"</tbody>\n",
"</table>\n"
],
"text/latex": [
"\\begin{tabular}{r|lll}\n",
" Sepal.Width & Petal.Length & Petal.Width\\\\\n",
"\\hline\n",
"\t 3.5 & 1.4 & 0.2\\\\\n",
"\t 3.0 & 1.4 & 0.2\\\\\n",
"\t 3.2 & 1.3 & 0.2\\\\\n",