{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Matrices" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Une matrice est un objet constitué de données en deux dimensions, soit des lignes et des colonnes. Chaque élément de la matrice est situé à l'intersection d'une ligne et d'une colonne." ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "A<- matrix(c(6,8,1,1,4,2), nrow = 2, ncol = 3)" ] }, { "cell_type": "code", "execution_count": 57, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\n", "
614
812
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t 6 & 1 & 4\\\\\n", "\t 8 & 1 & 2\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 6 | 1 | 4 | \n", "| 8 | 1 | 2 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 6 1 4 \n", "[2,] 8 1 2 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Il arrive souvent qu'on veuille transposer une matrice. Pour ce faire, il suffit de l'inclure à l'intérieur de `t(matrice)`" ] }, { "cell_type": "code", "execution_count": 58, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
68
11
42
\n" ], "text/latex": [ "\\begin{tabular}{ll}\n", "\t 6 & 8\\\\\n", "\t 1 & 1\\\\\n", "\t 4 & 2\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 6 | 8 | \n", "| 1 | 1 | \n", "| 4 | 2 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2]\n", "[1,] 6 8 \n", "[2,] 1 1 \n", "[3,] 4 2 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t(A)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "**Note** Lorsqu'on transpose un vecteur, R transforme ce vecteur en une matrice à une seule dimension:" ] }, { "cell_type": "code", "execution_count": 59, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "vec<-1:5" ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\n", "
12345
\n" ], "text/latex": [ "\\begin{tabular}{lllll}\n", "\t 1 & 2 & 3 & 4 & 5\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 1 | 2 | 3 | 4 | 5 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3] [,4] [,5]\n", "[1,] 1 2 3 4 5 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t(vec)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "**Note** la fonction `dim()` donne les dimensions d'une matrice. Si l’on vérifie la dimension du vecteur." ] }, { "cell_type": "code", "execution_count": 62, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "NULL" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dim(vec)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Bien évidemment il nous retourne une valeur nulle. Mais lorsqu'on transforme ce vecteur en matrice, on obtient;" ] }, { "cell_type": "code", "execution_count": 63, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. 1
  2. \n", "\t
  3. 5
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 1\n", "\\item 5\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 1\n", "2. 5\n", "\n", "\n" ], "text/plain": [ "[1] 1 5" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dim(t(vec))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Ce qui veut dire que notre matrice est composée d'une seule ligne et cinq colonnes" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Extraction d'un élément d'une matrice" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Si l'on veut extraire un élément d'une matrice, il suffit d'indiquer ses coordonnées **`[ligne, colonne]`**" ] }, { "cell_type": "code", "execution_count": 64, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "4" ], "text/latex": [ "4" ], "text/markdown": [ "4" ], "text/plain": [ "[1] 4" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A[1,3]" ] }, { "cell_type": "code", "execution_count": 65, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\n", "
614
812
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t 6 & 1 & 4\\\\\n", "\t 8 & 1 & 2\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 6 | 1 | 4 | \n", "| 8 | 1 | 2 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 6 1 4 \n", "[2,] 8 1 2 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Lorsqu'on veut extraire un élément qui n'existe pas dans la matrice, on obtien alors le message d'erreur `subscript out of bounds`. Un message d'erreur que nous verrons souvent!" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "ename": "ERROR", "evalue": "Error in A[1, 4]: subscript out of bounds\n", "output_type": "error", "traceback": [ "Error in A[1, 4]: subscript out of bounds\nTraceback:\n" ] } ], "source": [ "A[1,4]" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Si l'on omet de mettre une valeur au numéro de colonne ou de ligne, on obtient la ligne ou la colonne complète" ] }, { "cell_type": "code", "execution_count": 68, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. 6
  2. \n", "\t
  3. 8
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 6\n", "\\item 8\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 6\n", "2. 8\n", "\n", "\n" ], "text/plain": [ "[1] 6 8" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A[,1]" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Lorsqu'on crée une matrice, nous ne sommes pas obligés d'indiquer le nombre de colonnes ou de lignes en même temps. Un seul argument suffit." ] }, { "cell_type": "code", "execution_count": 81, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "B<-matrix(seq(1,9.5,.5), 3)" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
1.02.54.05.57.08.5
1.53.04.56.07.59.0
2.03.55.06.58.09.5
\n" ], "text/latex": [ "\\begin{tabular}{llllll}\n", "\t 1.0 & 2.5 & 4.0 & 5.5 & 7.0 & 8.5\\\\\n", "\t 1.5 & 3.0 & 4.5 & 6.0 & 7.5 & 9.0\\\\\n", "\t 2.0 & 3.5 & 5.0 & 6.5 & 8.0 & 9.5\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 1.0 | 2.5 | 4.0 | 5.5 | 7.0 | 8.5 | \n", "| 1.5 | 3.0 | 4.5 | 6.0 | 7.5 | 9.0 | \n", "| 2.0 | 3.5 | 5.0 | 6.5 | 8.0 | 9.5 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3] [,4] [,5] [,6]\n", "[1,] 1.0 2.5 4.0 5.5 7.0 8.5 \n", "[2,] 1.5 3.0 4.5 6.0 7.5 9.0 \n", "[3,] 2.0 3.5 5.0 6.5 8.0 9.5 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Si l'on veut extraire la deuxième et la quatrième colonne" ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
2.55.5
3.06.0
3.56.5
\n" ], "text/latex": [ "\\begin{tabular}{ll}\n", "\t 2.5 & 5.5\\\\\n", "\t 3.0 & 6.0\\\\\n", "\t 3.5 & 6.5\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 2.5 | 5.5 | \n", "| 3.0 | 6.0 | \n", "| 3.5 | 6.5 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2]\n", "[1,] 2.5 5.5 \n", "[2,] 3.0 6.0 \n", "[3,] 3.5 6.5 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B[,c(2,4)]" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "B<-t(B)" ] }, { "cell_type": "code", "execution_count": 79, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
1.01.52.0
2.53.03.5
4.04.55.0
5.56.06.5
7.07.58.0
8.59.09.5
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t 1.0 & 1.5 & 2.0\\\\\n", "\t 2.5 & 3.0 & 3.5\\\\\n", "\t 4.0 & 4.5 & 5.0\\\\\n", "\t 5.5 & 6.0 & 6.5\\\\\n", "\t 7.0 & 7.5 & 8.0\\\\\n", "\t 8.5 & 9.0 & 9.5\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 1.0 | 1.5 | 2.0 | \n", "| 2.5 | 3.0 | 3.5 | \n", "| 4.0 | 4.5 | 5.0 | \n", "| 5.5 | 6.0 | 6.5 | \n", "| 7.0 | 7.5 | 8.0 | \n", "| 8.5 | 9.0 | 9.5 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 1.0 1.5 2.0 \n", "[2,] 2.5 3.0 3.5 \n", "[3,] 4.0 4.5 5.0 \n", "[4,] 5.5 6.0 6.5 \n", "[5,] 7.0 7.5 8.0 \n", "[6,] 8.5 9.0 9.5 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Si l'on veut extraire la troisième et la cinquième ligne;" ] }, { "cell_type": "code", "execution_count": 80, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\n", "
4 4.55
7 7.58
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t 4 & 4.5 & 5 \\\\\n", "\t 7 & 7.5 & 8 \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 4 | 4.5 | 5 | \n", "| 7 | 7.5 | 8 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 4 4.5 5 \n", "[2,] 7 7.5 8 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B[c(3,5),]" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## diag" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Cette fonction crée une matrice identité, c'est une matrice carrée avec des 1 sur la diagonale et des 0 partout ailleurs." ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
10000
01000
00100
00010
00001
\n" ], "text/latex": [ "\\begin{tabular}{lllll}\n", "\t 1 & 0 & 0 & 0 & 0\\\\\n", "\t 0 & 1 & 0 & 0 & 0\\\\\n", "\t 0 & 0 & 1 & 0 & 0\\\\\n", "\t 0 & 0 & 0 & 1 & 0\\\\\n", "\t 0 & 0 & 0 & 0 & 1\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 1 | 0 | 0 | 0 | 0 | \n", "| 0 | 1 | 0 | 0 | 0 | \n", "| 0 | 0 | 1 | 0 | 0 | \n", "| 0 | 0 | 0 | 1 | 0 | \n", "| 0 | 0 | 0 | 0 | 1 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3] [,4] [,5]\n", "[1,] 1 0 0 0 0 \n", "[2,] 0 1 0 0 0 \n", "[3,] 0 0 1 0 0 \n", "[4,] 0 0 0 1 0 \n", "[5,] 0 0 0 0 1 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "diag(5)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Opértaion sur les matrices" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "On peut aussi appliquer des fonctions mathématiques sur des matrices comme nous l'avons fait avec des vecteurs" ] }, { "cell_type": "code", "execution_count": 85, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\n", "
361 16
641 4
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t 36 & 1 & 16\\\\\n", "\t 64 & 1 & 4\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 36 | 1 | 16 | \n", "| 64 | 1 | 4 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 36 1 16 \n", "[2,] 64 1 4 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A**2" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
0.501.252.002.753.504.25
0.751.502.253.003.754.50
1.001.752.503.254.004.75
\n" ], "text/latex": [ "\\begin{tabular}{llllll}\n", "\t 0.50 & 1.25 & 2.00 & 2.75 & 3.50 & 4.25\\\\\n", "\t 0.75 & 1.50 & 2.25 & 3.00 & 3.75 & 4.50\\\\\n", "\t 1.00 & 1.75 & 2.50 & 3.25 & 4.00 & 4.75\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 0.50 | 1.25 | 2.00 | 2.75 | 3.50 | 4.25 | \n", "| 0.75 | 1.50 | 2.25 | 3.00 | 3.75 | 4.50 | \n", "| 1.00 | 1.75 | 2.50 | 3.25 | 4.00 | 4.75 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3] [,4] [,5] [,6]\n", "[1,] 0.50 1.25 2.00 2.75 3.50 4.25\n", "[2,] 0.75 1.50 2.25 3.00 3.75 4.50\n", "[3,] 1.00 1.75 2.50 3.25 4.00 4.75" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B/2" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "C<-B*2" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
3.0 7.512.016.521.025.5
4.5 9.013.518.022.527.0
6.0 10.515.019.524.028.5
\n" ], "text/latex": [ "\\begin{tabular}{llllll}\n", "\t 3.0 & 7.5 & 12.0 & 16.5 & 21.0 & 25.5\\\\\n", "\t 4.5 & 9.0 & 13.5 & 18.0 & 22.5 & 27.0\\\\\n", "\t 6.0 & 10.5 & 15.0 & 19.5 & 24.0 & 28.5\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 3.0 | 7.5 | 12.0 | 16.5 | 21.0 | 25.5 | \n", "| 4.5 | 9.0 | 13.5 | 18.0 | 22.5 | 27.0 | \n", "| 6.0 | 10.5 | 15.0 | 19.5 | 24.0 | 28.5 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3] [,4] [,5] [,6]\n", "[1,] 3.0 7.5 12.0 16.5 21.0 25.5\n", "[2,] 4.5 9.0 13.5 18.0 22.5 27.0\n", "[3,] 6.0 10.5 15.0 19.5 24.0 28.5" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B+C" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Créons une matrice `A=5X3`. Cette matrice contient les températures en Fahrenheit des trois villes \"Fairbanks\",\"San Francisco\" et \"Chicago\" (nom de colonnes). Les lignes sont les données du mois de mars 2012 au mois de mars 2016." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
307255
326057
317856
276755
367149
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t 30 & 72 & 55\\\\\n", "\t 32 & 60 & 57\\\\\n", "\t 31 & 78 & 56\\\\\n", "\t 27 & 67 & 55\\\\\n", "\t 36 & 71 & 49\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| 30 | 72 | 55 | \n", "| 32 | 60 | 57 | \n", "| 31 | 78 | 56 | \n", "| 27 | 67 | 55 | \n", "| 36 | 71 | 49 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 30 72 55 \n", "[2,] 32 60 57 \n", "[3,] 31 78 56 \n", "[4,] 27 67 55 \n", "[5,] 36 71 49 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A<-matrix(c(30,32,31,27,36,72,60,78,67,71,55,57,56,55,49),ncol=3)\n", "A" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Convertissons ces données en Celsius avec la formule suivante;" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "\\begin{equation}\\label{eq:}\n", "℃= \\frac{℉-32}{1.8000}\n", "\\end{equation}\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
-12213
01614
-12613
-31913
222 9
\n" ], "text/latex": [ "\\begin{tabular}{lll}\n", "\t -1 & 22 & 13\\\\\n", "\t 0 & 16 & 14\\\\\n", "\t -1 & 26 & 13\\\\\n", "\t -3 & 19 & 13\\\\\n", "\t 2 & 22 & 9\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| -1 | 22 | 13 | \n", "| 0 | 16 | 14 | \n", "| -1 | 26 | 13 | \n", "| -3 | 19 | 13 | \n", "| 2 | 22 | 9 | \n", "\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] -1 22 13 \n", "[2,] 0 16 14 \n", "[3,] -1 26 13 \n", "[4,] -3 19 13 \n", "[5,] 2 22 9 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A<-round((A-32)/1.8,0)\n", "A" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "On peut donner des noms à chacune des colonnes avec la fonction `colnames()`" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "colnames(A)<-c(\"Fairbanks\",\"San Francisco\",\"Chicago\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "et des nom aux lignes avec la fonction `rownames()`" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "rownames(A)<-paste(\"3/\",12:16,sep='')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "La fonction `paste` ci-haut permet de concatener des caractères " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. '3/___12'
  2. \n", "\t
  3. '3/___13'
  4. \n", "\t
  5. '3/___14'
  6. \n", "\t
  7. '3/___15'
  8. \n", "\t
  9. '3/___16'
  10. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item '3/\\_\\_\\_12'\n", "\\item '3/\\_\\_\\_13'\n", "\\item '3/\\_\\_\\_14'\n", "\\item '3/\\_\\_\\_15'\n", "\\item '3/\\_\\_\\_16'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. '3/___12'\n", "2. '3/___13'\n", "3. '3/___14'\n", "4. '3/___15'\n", "5. '3/___16'\n", "\n", "\n" ], "text/plain": [ "[1] \"3/___12\" \"3/___13\" \"3/___14\" \"3/___15\" \"3/___16\"" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "paste(\"3/\",12:16,sep='___')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
FairbanksSan FranciscoChicago
3/12-12213
3/13 01614
3/14-12613
3/15-31913
3/16 222 9
\n" ], "text/latex": [ "\\begin{tabular}{r|lll}\n", " & Fairbanks & San Francisco & Chicago\\\\\n", "\\hline\n", "\t3/12 & -1 & 22 & 13\\\\\n", "\t3/13 & 0 & 16 & 14\\\\\n", "\t3/14 & -1 & 26 & 13\\\\\n", "\t3/15 & -3 & 19 & 13\\\\\n", "\t3/16 & 2 & 22 & 9\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Fairbanks | San Francisco | Chicago | \n", "|---|---|---|---|---|\n", "| 3/12 | -1 | 22 | 13 | \n", "| 3/13 | 0 | 16 | 14 | \n", "| 3/14 | -1 | 26 | 13 | \n", "| 3/15 | -3 | 19 | 13 | \n", "| 3/16 | 2 | 22 | 9 | \n", "\n", "\n" ], "text/plain": [ " Fairbanks San Francisco Chicago\n", "3/12 -1 22 13 \n", "3/13 0 16 14 \n", "3/14 -1 26 13 \n", "3/15 -3 19 13 \n", "3/16 2 22 9 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Créons une autre matrice `B`" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "B<-matrix(c(88,85,83,81,78,62,61,54,60,65,90,92,91,89,90),ncol=3)\n", "colnames(B)<-c(\"Los Angeles\",\"Seattle\",\"Honolulu\")\n", "rownames(B)<-paste(\"3/\",12:16,sep='')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
Los AngelesSeattleHonolulu
3/12311732
3/13291633
3/14281233
3/15271632
3/16261832
\n" ], "text/latex": [ "\\begin{tabular}{r|lll}\n", " & Los Angeles & Seattle & Honolulu\\\\\n", "\\hline\n", "\t3/12 & 31 & 17 & 32\\\\\n", "\t3/13 & 29 & 16 & 33\\\\\n", "\t3/14 & 28 & 12 & 33\\\\\n", "\t3/15 & 27 & 16 & 32\\\\\n", "\t3/16 & 26 & 18 & 32\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Los Angeles | Seattle | Honolulu | \n", "|---|---|---|---|---|\n", "| 3/12 | 31 | 17 | 32 | \n", "| 3/13 | 29 | 16 | 33 | \n", "| 3/14 | 28 | 12 | 33 | \n", "| 3/15 | 27 | 16 | 32 | \n", "| 3/16 | 26 | 18 | 32 | \n", "\n", "\n" ], "text/plain": [ " Los Angeles Seattle Honolulu\n", "3/12 31 17 32 \n", "3/13 29 16 33 \n", "3/14 28 12 33 \n", "3/15 27 16 32 \n", "3/16 26 18 32 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B<-round((B-32)/1.8,0)\n", "B" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## cbind" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "La fonction `cbind` permet de concaténer deux matrices ensemble en colonne" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
FairbanksSan FranciscoChicagoLos AngelesSeattleHonolulu
3/12-12213311732
3/13 01614291633
3/14-12613281233
3/15-31913271632
3/16 222 9261832
\n" ], "text/latex": [ "\\begin{tabular}{r|llllll}\n", " & Fairbanks & San Francisco & Chicago & Los Angeles & Seattle & Honolulu\\\\\n", "\\hline\n", "\t3/12 & -1 & 22 & 13 & 31 & 17 & 32\\\\\n", "\t3/13 & 0 & 16 & 14 & 29 & 16 & 33\\\\\n", "\t3/14 & -1 & 26 & 13 & 28 & 12 & 33\\\\\n", "\t3/15 & -3 & 19 & 13 & 27 & 16 & 32\\\\\n", "\t3/16 & 2 & 22 & 9 & 26 & 18 & 32\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Fairbanks | San Francisco | Chicago | Los Angeles | Seattle | Honolulu | \n", "|---|---|---|---|---|\n", "| 3/12 | -1 | 22 | 13 | 31 | 17 | 32 | \n", "| 3/13 | 0 | 16 | 14 | 29 | 16 | 33 | \n", "| 3/14 | -1 | 26 | 13 | 28 | 12 | 33 | \n", "| 3/15 | -3 | 19 | 13 | 27 | 16 | 32 | \n", "| 3/16 | 2 | 22 | 9 | 26 | 18 | 32 | \n", "\n", "\n" ], "text/plain": [ " Fairbanks San Francisco Chicago Los Angeles Seattle Honolulu\n", "3/12 -1 22 13 31 17 32 \n", "3/13 0 16 14 29 16 33 \n", "3/14 -1 26 13 28 12 33 \n", "3/15 -3 19 13 27 16 32 \n", "3/16 2 22 9 26 18 32 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cbind(A,B)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## rbind" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "La fonction `rbind` permet de concaténer deux matrices ensemble une par-dessus l'autre" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
FairbanksSan FranciscoChicago
3/12-12213
3/13 01614
3/14-12613
3/15-31913
3/16 222 9
3/12311732
3/13291633
3/14281233
3/15271632
3/16261832
\n" ], "text/latex": [ "\\begin{tabular}{r|lll}\n", " & Fairbanks & San Francisco & Chicago\\\\\n", "\\hline\n", "\t3/12 & -1 & 22 & 13\\\\\n", "\t3/13 & 0 & 16 & 14\\\\\n", "\t3/14 & -1 & 26 & 13\\\\\n", "\t3/15 & -3 & 19 & 13\\\\\n", "\t3/16 & 2 & 22 & 9\\\\\n", "\t3/12 & 31 & 17 & 32\\\\\n", "\t3/13 & 29 & 16 & 33\\\\\n", "\t3/14 & 28 & 12 & 33\\\\\n", "\t3/15 & 27 & 16 & 32\\\\\n", "\t3/16 & 26 & 18 & 32\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Fairbanks | San Francisco | Chicago | \n", "|---|---|---|---|---|---|---|---|---|---|\n", "| 3/12 | -1 | 22 | 13 | \n", "| 3/13 | 0 | 16 | 14 | \n", "| 3/14 | -1 | 26 | 13 | \n", "| 3/15 | -3 | 19 | 13 | \n", "| 3/16 | 2 | 22 | 9 | \n", "| 3/12 | 31 | 17 | 32 | \n", "| 3/13 | 29 | 16 | 33 | \n", "| 3/14 | 28 | 12 | 33 | \n", "| 3/15 | 27 | 16 | 32 | \n", "| 3/16 | 26 | 18 | 32 | \n", "\n", "\n" ], "text/plain": [ " Fairbanks San Francisco Chicago\n", "3/12 -1 22 13 \n", "3/13 0 16 14 \n", "3/14 -1 26 13 \n", "3/15 -3 19 13 \n", "3/16 2 22 9 \n", "3/12 31 17 32 \n", "3/13 29 16 33 \n", "3/14 28 12 33 \n", "3/15 27 16 32 \n", "3/16 26 18 32 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "rbind(A,B)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## matrcice en vecteur" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "On peut aussi transformer une matrice en un vecteur;" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Reprenons la matrice que nous avons créée avec la fonction `rbind`. On lui donne le nom \"mat_comb\"" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "mat_comb<-cbind(A,B)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "On la transforme en vecteur avec `c(nomMatrice)`" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. -1
  2. \n", "\t
  3. 0
  4. \n", "\t
  5. -1
  6. \n", "\t
  7. -3
  8. \n", "\t
  9. 2
  10. \n", "\t
  11. 22
  12. \n", "\t
  13. 16
  14. \n", "\t
  15. 26
  16. \n", "\t
  17. 19
  18. \n", "\t
  19. 22
  20. \n", "\t
  21. 13
  22. \n", "\t
  23. 14
  24. \n", "\t
  25. 13
  26. \n", "\t
  27. 13
  28. \n", "\t
  29. 9
  30. \n", "\t
  31. 31
  32. \n", "\t
  33. 29
  34. \n", "\t
  35. 28
  36. \n", "\t
  37. 27
  38. \n", "\t
  39. 26
  40. \n", "\t
  41. 17
  42. \n", "\t
  43. 16
  44. \n", "\t
  45. 12
  46. \n", "\t
  47. 16
  48. \n", "\t
  49. 18
  50. \n", "\t
  51. 32
  52. \n", "\t
  53. 33
  54. \n", "\t
  55. 33
  56. \n", "\t
  57. 32
  58. \n", "\t
  59. 32
  60. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item -1\n", "\\item 0\n", "\\item -1\n", "\\item -3\n", "\\item 2\n", "\\item 22\n", "\\item 16\n", "\\item 26\n", "\\item 19\n", "\\item 22\n", "\\item 13\n", "\\item 14\n", "\\item 13\n", "\\item 13\n", "\\item 9\n", "\\item 31\n", "\\item 29\n", "\\item 28\n", "\\item 27\n", "\\item 26\n", "\\item 17\n", "\\item 16\n", "\\item 12\n", "\\item 16\n", "\\item 18\n", "\\item 32\n", "\\item 33\n", "\\item 33\n", "\\item 32\n", "\\item 32\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. -1\n", "2. 0\n", "3. -1\n", "4. -3\n", "5. 2\n", "6. 22\n", "7. 16\n", "8. 26\n", "9. 19\n", "10. 22\n", "11. 13\n", "12. 14\n", "13. 13\n", "14. 13\n", "15. 9\n", "16. 31\n", "17. 29\n", "18. 28\n", "19. 27\n", "20. 26\n", "21. 17\n", "22. 16\n", "23. 12\n", "24. 16\n", "25. 18\n", "26. 32\n", "27. 33\n", "28. 33\n", "29. 32\n", "30. 32\n", "\n", "\n" ], "text/plain": [ " [1] -1 0 -1 -3 2 22 16 26 19 22 13 14 13 13 9 31 29 28 27 26 17 16 12 16 18\n", "[26] 32 33 33 32 32" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "c(mat_comb)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Quelques fonctions statistiques sur les matrices" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
FairbanksSan FranciscoChicagoLos AngelesSeattleHonolulu
3/12-12213311732
3/13 01614291633
3/14-12613281233
3/15-31913271632
3/16 222 9261832
\n" ], "text/latex": [ "\\begin{tabular}{r|llllll}\n", " & Fairbanks & San Francisco & Chicago & Los Angeles & Seattle & Honolulu\\\\\n", "\\hline\n", "\t3/12 & -1 & 22 & 13 & 31 & 17 & 32\\\\\n", "\t3/13 & 0 & 16 & 14 & 29 & 16 & 33\\\\\n", "\t3/14 & -1 & 26 & 13 & 28 & 12 & 33\\\\\n", "\t3/15 & -3 & 19 & 13 & 27 & 16 & 32\\\\\n", "\t3/16 & 2 & 22 & 9 & 26 & 18 & 32\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Fairbanks | San Francisco | Chicago | Los Angeles | Seattle | Honolulu | \n", "|---|---|---|---|---|\n", "| 3/12 | -1 | 22 | 13 | 31 | 17 | 32 | \n", "| 3/13 | 0 | 16 | 14 | 29 | 16 | 33 | \n", "| 3/14 | -1 | 26 | 13 | 28 | 12 | 33 | \n", "| 3/15 | -3 | 19 | 13 | 27 | 16 | 32 | \n", "| 3/16 | 2 | 22 | 9 | 26 | 18 | 32 | \n", "\n", "\n" ], "text/plain": [ " Fairbanks San Francisco Chicago Los Angeles Seattle Honolulu\n", "3/12 -1 22 13 31 17 32 \n", "3/13 0 16 14 29 16 33 \n", "3/14 -1 26 13 28 12 33 \n", "3/15 -3 19 13 27 16 32 \n", "3/16 2 22 9 26 18 32 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mat_comb" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Lorsqu'on applique la fonction `min`, on obtient alors la valeur minimale de toutes les valeurs contenues dans la matrice" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "-3" ], "text/latex": [ "-3" ], "text/markdown": [ "-3" ], "text/plain": [ "[1] -3" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "min(mat_comb)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "33" ], "text/latex": [ "33" ], "text/markdown": [ "33" ], "text/plain": [ "[1] 33" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "max(mat_comb)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. -3
  2. \n", "\t
  3. 33
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item -3\n", "\\item 33\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. -3\n", "2. 33\n", "\n", "\n" ], "text/plain": [ "[1] -3 33" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "range(mat_comb)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "11.1923619275487" ], "text/latex": [ "11.1923619275487" ], "text/markdown": [ "11.1923619275487" ], "text/plain": [ "[1] 11.19236" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sd(mat_comb)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Les statistiques que nous venons d'obtenir, sont applquées à toutes les valeurs de la matrice. Et si nous voulions des statistiques par ligne ou par colonne" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\t
3/12
\n", "\t\t
19
\n", "\t
3/13
\n", "\t\t
18
\n", "\t
3/14
\n", "\t\t
18.5
\n", "\t
3/15
\n", "\t\t
17.3333333333333
\n", "\t
3/16
\n", "\t\t
18.1666666666667
\n", "
\n" ], "text/latex": [ "\\begin{description*}\n", "\\item[3/12] 19\n", "\\item[3/13] 18\n", "\\item[3/14] 18.5\n", "\\item[3/15] 17.3333333333333\n", "\\item[3/16] 18.1666666666667\n", "\\end{description*}\n" ], "text/markdown": [ "3/12\n", ": 193/13\n", ": 183/14\n", ": 18.53/15\n", ": 17.33333333333333/16\n", ": 18.1666666666667\n", "\n" ], "text/plain": [ " 3/12 3/13 3/14 3/15 3/16 \n", "19.00000 18.00000 18.50000 17.33333 18.16667 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "rowMeans(mat_comb)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\t
Fairbanks
\n", "\t\t
-0.6
\n", "\t
San Francisco
\n", "\t\t
21
\n", "\t
Chicago
\n", "\t\t
12.4
\n", "\t
Los Angeles
\n", "\t\t
28.2
\n", "\t
Seattle
\n", "\t\t
15.8
\n", "\t
Honolulu
\n", "\t\t
32.4
\n", "
\n" ], "text/latex": [ "\\begin{description*}\n", "\\item[Fairbanks] -0.6\n", "\\item[San Francisco] 21\n", "\\item[Chicago] 12.4\n", "\\item[Los Angeles] 28.2\n", "\\item[Seattle] 15.8\n", "\\item[Honolulu] 32.4\n", "\\end{description*}\n" ], "text/markdown": [ "Fairbanks\n", ": -0.6San Francisco\n", ": 21Chicago\n", ": 12.4Los Angeles\n", ": 28.2Seattle\n", ": 15.8Honolulu\n", ": 32.4\n", "\n" ], "text/plain": [ " Fairbanks San Francisco Chicago Los Angeles Seattle \n", " -0.6 21.0 12.4 28.2 15.8 \n", " Honolulu \n", " 32.4 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "colMeans(mat_comb)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Corrélation" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
FairbanksSan FranciscoChicagoLos AngelesSeattleHonolulu
Fairbanks 1.00000000 0.07356124-0.6918586 -0.24325462 0.38624364 0.05025189
San Francisco 0.07356124 1.00000000-0.3084798 -0.06947125-0.49810768 0.00000000
Chicago-0.69185856-0.30847978 1.0000000 0.64005690-0.48366537 0.51512220
Los Angeles-0.24325462-0.06947125 0.6400569 1.00000000-0.04559608 0.14237370
Seattle 0.38624364-0.49810768-0.4836654 -0.04559608 1.00000000-0.72057669
Honolulu 0.05025189 0.00000000 0.5151222 0.14237370-0.72057669 1.00000000
\n" ], "text/latex": [ "\\begin{tabular}{r|llllll}\n", " & Fairbanks & San Francisco & Chicago & Los Angeles & Seattle & Honolulu\\\\\n", "\\hline\n", "\tFairbanks & 1.00000000 & 0.07356124 & -0.6918586 & -0.24325462 & 0.38624364 & 0.05025189\\\\\n", "\tSan Francisco & 0.07356124 & 1.00000000 & -0.3084798 & -0.06947125 & -0.49810768 & 0.00000000\\\\\n", "\tChicago & -0.69185856 & -0.30847978 & 1.0000000 & 0.64005690 & -0.48366537 & 0.51512220\\\\\n", "\tLos Angeles & -0.24325462 & -0.06947125 & 0.6400569 & 1.00000000 & -0.04559608 & 0.14237370\\\\\n", "\tSeattle & 0.38624364 & -0.49810768 & -0.4836654 & -0.04559608 & 1.00000000 & -0.72057669\\\\\n", "\tHonolulu & 0.05025189 & 0.00000000 & 0.5151222 & 0.14237370 & -0.72057669 & 1.00000000\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Fairbanks | San Francisco | Chicago | Los Angeles | Seattle | Honolulu | \n", "|---|---|---|---|---|---|\n", "| Fairbanks | 1.00000000 | 0.07356124 | -0.6918586 | -0.24325462 | 0.38624364 | 0.05025189 | \n", "| San Francisco | 0.07356124 | 1.00000000 | -0.3084798 | -0.06947125 | -0.49810768 | 0.00000000 | \n", "| Chicago | -0.69185856 | -0.30847978 | 1.0000000 | 0.64005690 | -0.48366537 | 0.51512220 | \n", "| Los Angeles | -0.24325462 | -0.06947125 | 0.6400569 | 1.00000000 | -0.04559608 | 0.14237370 | \n", "| Seattle | 0.38624364 | -0.49810768 | -0.4836654 | -0.04559608 | 1.00000000 | -0.72057669 | \n", "| Honolulu | 0.05025189 | 0.00000000 | 0.5151222 | 0.14237370 | -0.72057669 | 1.00000000 | \n", "\n", "\n" ], "text/plain": [ " Fairbanks San Francisco Chicago Los Angeles Seattle \n", "Fairbanks 1.00000000 0.07356124 -0.6918586 -0.24325462 0.38624364\n", "San Francisco 0.07356124 1.00000000 -0.3084798 -0.06947125 -0.49810768\n", "Chicago -0.69185856 -0.30847978 1.0000000 0.64005690 -0.48366537\n", "Los Angeles -0.24325462 -0.06947125 0.6400569 1.00000000 -0.04559608\n", "Seattle 0.38624364 -0.49810768 -0.4836654 -0.04559608 1.00000000\n", "Honolulu 0.05025189 0.00000000 0.5151222 0.14237370 -0.72057669\n", " Honolulu \n", "Fairbanks 0.05025189\n", "San Francisco 0.00000000\n", "Chicago 0.51512220\n", "Los Angeles 0.14237370\n", "Seattle -0.72057669\n", "Honolulu 1.00000000" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cor(mat_comb)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## summary" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/plain": [ " Fairbanks San Francisco Chicago Los Angeles Seattle \n", " Min. :-3.0 Min. :16 Min. : 9.0 Min. :26.0 Min. :12.0 \n", " 1st Qu.:-1.0 1st Qu.:19 1st Qu.:13.0 1st Qu.:27.0 1st Qu.:16.0 \n", " Median :-1.0 Median :22 Median :13.0 Median :28.0 Median :16.0 \n", " Mean :-0.6 Mean :21 Mean :12.4 Mean :28.2 Mean :15.8 \n", " 3rd Qu.: 0.0 3rd Qu.:22 3rd Qu.:13.0 3rd Qu.:29.0 3rd Qu.:17.0 \n", " Max. : 2.0 Max. :26 Max. :14.0 Max. :31.0 Max. :18.0 \n", " Honolulu \n", " Min. :32.0 \n", " 1st Qu.:32.0 \n", " Median :32.0 \n", " Mean :32.4 \n", " 3rd Qu.:33.0 \n", " Max. :33.0 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "summary(mat_comb)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ " Si on veut par ligne, rappelons-nous que nous avons appris à transposer les matrices!" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ " 3/12 3/13 3/14 3/15 \n", " Min. :-1.00 Min. : 0.00 Min. :-1.00 Min. :-3.00 \n", " 1st Qu.:14.00 1st Qu.:14.50 1st Qu.:12.25 1st Qu.:13.75 \n", " Median :19.50 Median :16.00 Median :19.50 Median :17.50 \n", " Mean :19.00 Mean :18.00 Mean :18.50 Mean :17.33 \n", " 3rd Qu.:28.75 3rd Qu.:25.75 3rd Qu.:27.50 3rd Qu.:25.00 \n", " Max. :32.00 Max. :33.00 Max. :33.00 Max. :32.00 \n", " 3/16 \n", " Min. : 2.00 \n", " 1st Qu.:11.25 \n", " Median :20.00 \n", " Mean :18.17 \n", " 3rd Qu.:25.00 \n", " Max. :32.00 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "summary(t(mat_comb))" ] } ], "metadata": { "anaconda-cloud": {}, "celltoolbar": "Slideshow", "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "4.1.2" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "name": "_merged", "toc": { "base_numbering": 1, "nav_menu": { "height": "512px", "width": "252px" }, "number_sections": false, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": { "height": "596px", "left": "0px", "right": "1017px", "top": "107px", "width": "250px" }, "toc_section_display": "block", "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }