{ "cells": [ { "cell_type": "markdown", "id": "8d42fc52", "metadata": {}, "source": [ "#### Installation of R packages" ] }, { "cell_type": "code", "execution_count": 1, "id": "52ac0f54", "metadata": {}, "outputs": [], "source": [ "#install.packages(\"ISwR\")" ] }, { "cell_type": "markdown", "id": "3a957ba3", "metadata": {}, "source": [ "#### Package loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "de33e724", "metadata": {}, "outputs": [], "source": [ "library(ISwR)" ] }, { "cell_type": "markdown", "id": "99bcc6a7", "metadata": {}, "source": [ "#### Variable definition and assignment" ] }, { "cell_type": "code", "execution_count": 3, "id": "1d0c4a11", "metadata": {}, "outputs": [], "source": [ "weight <- 60\n", "height = 1.75\n", "subject <- \"A\"\n", "healthy <- TRUE" ] }, { "cell_type": "markdown", "id": "bcee452b", "metadata": {}, "source": [ "#### Variable evaluation" ] }, { "cell_type": "code", "execution_count": 4, "id": "ad938581", "metadata": {}, "outputs": [ { "data": { "text/html": [ "60" ], "text/latex": [ "60" ], "text/markdown": [ "60" ], "text/plain": [ "[1] 60" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "weight" ] }, { "cell_type": "markdown", "id": "57dd208e", "metadata": {}, "source": [ "#### Functions for type checking" ] }, { "cell_type": "code", "execution_count": 5, "id": "1778ae3b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "FALSE" ], "text/latex": [ "FALSE" ], "text/markdown": [ "FALSE" ], "text/plain": [ "[1] FALSE" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "is.numeric(weight) # variable \n", "is.double(weight)\n", "is.integer(weight)\n", "is.character(subject)" ] }, { "cell_type": "markdown", "id": "5dcfe56a", "metadata": {}, "source": [ "#### Functions for variable conversion" ] }, { "cell_type": "code", "execution_count": 6, "id": "9de5f0fd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "weight <- as.integer(weight)\n", "is.integer(weight)" ] }, { "cell_type": "markdown", "id": "ecb65b7e", "metadata": {}, "source": [ "#### Computing the body mass index (BMI) from the weight and height" ] }, { "cell_type": "code", "execution_count": 7, "id": "5bb310e3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "19.5918367346939" ], "text/latex": [ "19.5918367346939" ], "text/markdown": [ "19.5918367346939" ], "text/plain": [ "[1] 19.59184" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#Body mass index (BMI)\n", "bmi <- weight/height^2 \n", "bmi " ] }, { "cell_type": "markdown", "id": "1d6b02ea", "metadata": {}, "source": [ "#### Functions for string manipulation" ] }, { "cell_type": "code", "execution_count": 8, "id": "2a5c0c64", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1] \"19.6\"\n" ] } ], "source": [ "message <- sprintf(\"%.1f\", bmi)\n", "print(message)" ] }, { "cell_type": "markdown", "id": "f465aa65", "metadata": {}, "source": [ "#### Vector definition" ] }, { "cell_type": "code", "execution_count": 9, "id": "f5792a41", "metadata": {}, "outputs": [], "source": [ "weight <- c(60, 72, 57, 90, 95, 72) \n", "height <- c(1.75, 1.80, 1.65, 1.90, 1.74, 1.91)\n", "subject <- c(\"A\", \"B\", \"C\", \"D\", \"E\", \"F\")\n" ] }, { "cell_type": "markdown", "id": "1c86ae38", "metadata": {}, "source": [ "#### Vector evaluation" ] }, { "cell_type": "code", "execution_count": 10, "id": "ea73ae27", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 60
  2. 72
  3. 57
  4. 90
  5. 95
  6. 72
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 60\n", "\\item 72\n", "\\item 57\n", "\\item 90\n", "\\item 95\n", "\\item 72\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 60\n", "2. 72\n", "3. 57\n", "4. 90\n", "5. 95\n", "6. 72\n", "\n", "\n" ], "text/plain": [ "[1] 60 72 57 90 95 72" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
  1. 1.75
  2. 1.8
  3. 1.65
  4. 1.9
  5. 1.74
  6. 1.91
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 1.75\n", "\\item 1.8\n", "\\item 1.65\n", "\\item 1.9\n", "\\item 1.74\n", "\\item 1.91\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 1.75\n", "2. 1.8\n", "3. 1.65\n", "4. 1.9\n", "5. 1.74\n", "6. 1.91\n", "\n", "\n" ], "text/plain": [ "[1] 1.75 1.80 1.65 1.90 1.74 1.91" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
  1. 'A'
  2. 'B'
  3. 'C'
  4. 'D'
  5. 'E'
  6. 'F'
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 'A'\n", "\\item 'B'\n", "\\item 'C'\n", "\\item 'D'\n", "\\item 'E'\n", "\\item 'F'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 'A'\n", "2. 'B'\n", "3. 'C'\n", "4. 'D'\n", "5. 'E'\n", "6. 'F'\n", "\n", "\n" ], "text/plain": [ "[1] \"A\" \"B\" \"C\" \"D\" \"E\" \"F\"" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "weight\n", "height\n", "subject" ] }, { "cell_type": "markdown", "id": "5502a330", "metadata": {}, "source": [ "#### Creating a vector with a particular size" ] }, { "cell_type": "code", "execution_count": 11, "id": "4e59d217", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 0
  2. 0
  3. 0
  4. 0
  5. 0
  6. 0
  7. 0
  8. 0
  9. 0
  10. 0
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\item 0\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 0\n", "2. 0\n", "3. 0\n", "4. 0\n", "5. 0\n", "6. 0\n", "7. 0\n", "8. 0\n", "9. 0\n", "10. 0\n", "\n", "\n" ], "text/plain": [ " [1] 0 0 0 0 0 0 0 0 0 0" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "vec <- rep(0, 10)\n", "vec" ] }, { "cell_type": "markdown", "id": "6689bea8", "metadata": {}, "source": [ "#### Vector length" ] }, { "cell_type": "code", "execution_count": 12, "id": "8b9a291b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "6" ], "text/latex": [ "6" ], "text/markdown": [ "6" ], "text/plain": [ "[1] 6" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "length(weight)\n" ] }, { "cell_type": "markdown", "id": "e2bfeacd", "metadata": {}, "source": [ "#### Vector indexes: from one to the length of the vector" ] }, { "cell_type": "code", "execution_count": 13, "id": "be37ba67", "metadata": {}, "outputs": [ { "data": { "text/html": [ "60" ], "text/latex": [ "60" ], "text/markdown": [ "60" ], "text/plain": [ "[1] 60" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "72" ], "text/latex": [ "72" ], "text/markdown": [ "72" ], "text/plain": [ "[1] 72" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "weight[1]\n", "weight[length(weight)]" ] }, { "cell_type": "markdown", "id": "8e052e4d", "metadata": {}, "source": [ "#### Iteration: for loop\n", "from one to the length of weight" ] }, { "cell_type": "code", "execution_count": 14, "id": "d89d1ae9", "metadata": {}, "outputs": [], "source": [ "bmi <- 0\n", "for (i in 1:length(weight)) {\n", " bmi[i] <- weight[i]/height[i]^2\n", "}\n" ] }, { "cell_type": "markdown", "id": "44062e04", "metadata": {}, "source": [ "evaluation of the bmi vector" ] }, { "cell_type": "code", "execution_count": 15, "id": "3bc6e592", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 19.5918367346939
  2. 22.2222222222222
  3. 20.9366391184573
  4. 24.9307479224377
  5. 31.3779891663364
  6. 19.7363010882377
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 19.5918367346939\n", "\\item 22.2222222222222\n", "\\item 20.9366391184573\n", "\\item 24.9307479224377\n", "\\item 31.3779891663364\n", "\\item 19.7363010882377\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 19.5918367346939\n", "2. 22.2222222222222\n", "3. 20.9366391184573\n", "4. 24.9307479224377\n", "5. 31.3779891663364\n", "6. 19.7363010882377\n", "\n", "\n" ], "text/plain": [ "[1] 19.59184 22.22222 20.93664 24.93075 31.37799 19.73630" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bmi" ] }, { "cell_type": "markdown", "id": "78af2d5a", "metadata": {}, "source": [ "#### Iteration: while loop\n", "run while i is below or equal to the length of weight" ] }, { "cell_type": "code", "execution_count": 16, "id": "708de5df", "metadata": {}, "outputs": [], "source": [ "bmi <- 0\n", "i <- 1\n", "while (i <= length(weight)) {\n", " bmi[i] <- weight[i]/height[i]^2\n", " i <- i + 1\n", "}\n" ] }, { "cell_type": "code", "execution_count": 17, "id": "7449e07e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 19.5918367346939
  2. 22.2222222222222
  3. 20.9366391184573
  4. 24.9307479224377
  5. 31.3779891663364
  6. 19.7363010882377
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 19.5918367346939\n", "\\item 22.2222222222222\n", "\\item 20.9366391184573\n", "\\item 24.9307479224377\n", "\\item 31.3779891663364\n", "\\item 19.7363010882377\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 19.5918367346939\n", "2. 22.2222222222222\n", "3. 20.9366391184573\n", "4. 24.9307479224377\n", "5. 31.3779891663364\n", "6. 19.7363010882377\n", "\n", "\n" ], "text/plain": [ "[1] 19.59184 22.22222 20.93664 24.93075 31.37799 19.73630" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bmi" ] }, { "cell_type": "markdown", "id": "9394fcf5", "metadata": {}, "source": [ "#### Remove a variable" ] }, { "cell_type": "code", "execution_count": 18, "id": "2c181a87", "metadata": {}, "outputs": [ { "data": { "text/html": [ "FALSE" ], "text/latex": [ "FALSE" ], "text/markdown": [ "FALSE" ], "text/plain": [ "[1] FALSE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "rm(bmi)\n", "exists(\"bmi\")" ] }, { "cell_type": "markdown", "id": "6203ac32", "metadata": {}, "source": [ "#### Right way of manipulating vectors: assigning at once" ] }, { "cell_type": "code", "execution_count": 19, "id": "6e6712a2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 19.5918367346939
  2. 22.2222222222222
  3. 20.9366391184573
  4. 24.9307479224377
  5. 31.3779891663364
  6. 19.7363010882377
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 19.5918367346939\n", "\\item 22.2222222222222\n", "\\item 20.9366391184573\n", "\\item 24.9307479224377\n", "\\item 31.3779891663364\n", "\\item 19.7363010882377\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 19.5918367346939\n", "2. 22.2222222222222\n", "3. 20.9366391184573\n", "4. 24.9307479224377\n", "5. 31.3779891663364\n", "6. 19.7363010882377\n", "\n", "\n" ], "text/plain": [ "[1] 19.59184 22.22222 20.93664 24.93075 31.37799 19.73630" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bmi <- weight/height^2 \n", "bmi " ] }, { "cell_type": "markdown", "id": "f654b0ff", "metadata": {}, "source": [ "#### Creating a function\n", "name <- function(parameters) { body }" ] }, { "cell_type": "code", "execution_count": 20, "id": "682911c9", "metadata": {}, "outputs": [], "source": [ "compute_bmi <- function(weight, height) {\n", " bmi <- weight/height^2 \n", " return(bmi)\n", "}" ] }, { "cell_type": "markdown", "id": "4cd72edd", "metadata": {}, "source": [ "#### Using a function with scalars" ] }, { "cell_type": "code", "execution_count": 21, "id": "abd58d44", "metadata": {}, "outputs": [ { "data": { "text/html": [ "19.5918367346939" ], "text/latex": [ "19.5918367346939" ], "text/markdown": [ "19.5918367346939" ], "text/plain": [ "[1] 19.59184" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "\n", "bmi <- compute_bmi(60, 1.75)\n", "bmi\n" ] }, { "cell_type": "markdown", "id": "9df8b472", "metadata": {}, "source": [ "#### Using the same function with vectors" ] }, { "cell_type": "code", "execution_count": 22, "id": "90db70cb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 19.5918367346939
  2. 22.2222222222222
  3. 20.9366391184573
  4. 24.9307479224377
  5. 31.3779891663364
  6. 19.7363010882377
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 19.5918367346939\n", "\\item 22.2222222222222\n", "\\item 20.9366391184573\n", "\\item 24.9307479224377\n", "\\item 31.3779891663364\n", "\\item 19.7363010882377\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 19.5918367346939\n", "2. 22.2222222222222\n", "3. 20.9366391184573\n", "4. 24.9307479224377\n", "5. 31.3779891663364\n", "6. 19.7363010882377\n", "\n", "\n" ], "text/plain": [ "[1] 19.59184 22.22222 20.93664 24.93075 31.37799 19.73630" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "bmi <- compute_bmi(weight, height)\n", "bmi" ] }, { "cell_type": "markdown", "id": "c7e11f53", "metadata": {}, "source": [ "#### Example of a function to compute the average\n", "(iterating in all elements of the vector)" ] }, { "cell_type": "code", "execution_count": 23, "id": "67374bc5", "metadata": {}, "outputs": [], "source": [ "average <- function(vec) {\n", " s <- 0\n", " n <- length(vec)\n", " for (x in vec) {\n", " s <- s + x \n", " }\n", " return(s/n)\n", "}" ] }, { "cell_type": "markdown", "id": "b683d41d", "metadata": {}, "source": [ "invoking the function" ] }, { "cell_type": "code", "execution_count": 24, "id": "8af439bb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "23.1326227087309" ], "text/latex": [ "23.1326227087309" ], "text/markdown": [ "23.1326227087309" ], "text/plain": [ "[1] 23.13262" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "avg_bmi <- average(bmi)\n", "avg_bmi" ] }, { "cell_type": "markdown", "id": "7925f58c", "metadata": {}, "source": [ "#### Example of a function to compute the average\n", "(manipulating vectors at once)" ] }, { "cell_type": "code", "execution_count": 25, "id": "d81ade80", "metadata": {}, "outputs": [], "source": [ "average <- function(vec) {\n", " s <- sum(vec)\n", " n <- length(vec)\n", " return(s/n)\n", "}" ] }, { "cell_type": "markdown", "id": "e85fe370", "metadata": {}, "source": [ "invoking the function" ] }, { "cell_type": "code", "execution_count": 26, "id": "acd8835e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "23.1326227087309" ], "text/latex": [ "23.1326227087309" ], "text/markdown": [ "23.1326227087309" ], "text/plain": [ "[1] 23.13262" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "avg_bmi <- average(bmi)\n", "avg_bmi" ] }, { "cell_type": "markdown", "id": "29d0264b", "metadata": {}, "source": [ "#### Average function using mean function\n", "Major statistical functions are available in R" ] }, { "cell_type": "code", "execution_count": 27, "id": "f46e574c", "metadata": {}, "outputs": [], "source": [ "average <- function(vec) {\n", " return(mean(vec))\n", "}" ] }, { "cell_type": "markdown", "id": "0a6609d2", "metadata": {}, "source": [ "invoking the function" ] }, { "cell_type": "code", "execution_count": 28, "id": "82116583", "metadata": {}, "outputs": [ { "data": { "text/html": [ "23.1326227087309" ], "text/latex": [ "23.1326227087309" ], "text/markdown": [ "23.1326227087309" ], "text/plain": [ "[1] 23.13262" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "avg_bmi <- average(bmi)\n", "avg_bmi" ] }, { "cell_type": "markdown", "id": "cd0eded4", "metadata": {}, "source": [ "#### Working with vectors with NA\n", "Operations with NA lead to NA." ] }, { "cell_type": "code", "execution_count": 29, "id": "a76dcffa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<NA>" ], "text/latex": [ "" ], "text/markdown": [ "<NA>" ], "text/plain": [ "[1] NA" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x <- c(10, NA, 13)\n", "y <- average(x)\n", "y" ] }, { "cell_type": "markdown", "id": "ad2e1300", "metadata": {}, "source": [ "#### addressing NA with na.rm=TRUE" ] }, { "cell_type": "code", "execution_count": 30, "id": "38a57461", "metadata": {}, "outputs": [], "source": [ "average <- function(vec) {\n", " return(mean(vec, na.rm=TRUE))\n", "}" ] }, { "cell_type": "code", "execution_count": 31, "id": "6fc66146", "metadata": {}, "outputs": [ { "data": { "text/html": [ "11.5" ], "text/latex": [ "11.5" ], "text/markdown": [ "11.5" ], "text/plain": [ "[1] 11.5" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x <- c(10, NA, 13)\n", "y <- average(x)\n", "y" ] }, { "cell_type": "markdown", "id": "5143eaa8", "metadata": {}, "source": [ "#### Plotting graphics\n", "scatter plots" ] }, { "cell_type": "code", "execution_count": 32, "id": "5bc25389", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAMAAADKOT/pAAAC+lBMVEUAAAABAQECAgIDAwME\nBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUW\nFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJyco\nKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6\nOjo7Ozs8PDw9PT0+Pj4/Pz9AQ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1VNLN9aP1avD3L8GGnIguTZolF2c8hAQkJ0xhTMXB+suDbv/vp8kNtn7SaYte09\nfERRe7OxFSHjCAmReTF3XuJ4V35ZPT7K8etIb5UUxF9HKix5MXQYISEyFwxNHre3qM+dO/fv\nbFi3ZEWt72xY0qVDlUPty5TmAPbakGmVJz2vr8dHOQ9p+5L3P15b60p++b9VfmgbU5kD2Htn\nXFB5cuxt9fgoxyH9ZVCD2F07azH549Bh/0NIiMrNRySf+V6c/Wo9PsptSOda05Na2BF9D7Oc\nR8PGERIis6b5lPhjjw39eoY9H/Z1TkP6hU3aEuy4osmC4LVeeS+EDCQkROeFZidefd8lbY5c\nWp8PchpSUbd46hXHD4313rZfyEBCQoSWTut/ZPGMTfX6GKchNR2XOIw7OHYxumnIQEKCZ5yG\n1PV7icOwdrGLXoUhAwkJnnEa0iR7Inb5Qs6ZQcUj2f8RMpCQ4BmnIZUVWv+Jg7IP+DC41w76\nKGQgIcEzbp/+XjIs26zba0Hw4DmfhI0jJHjG9TsbNs1b+Q1GERI8k5k/jouQ4BlCAgQICRAg\nJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRA\ngJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQ\nAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAAB\nQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUIC\nBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQI\nCRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQ\nICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAk\nQICQAAFCAgQICRAgJECAkAABQgIECAk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21XLtSPsGg+AMIWW8+oY0+/Cn070k7IaQMl7tIa1d\nVtegZ2xmupeE3RBSxvtG99oIKWKElPFKbc30Ew88+oH4+Y7rezQ5fPLy2NmZ8X+5Nee2azd2\nbUFpzUEDLGZttEveDxFSxiu1fu2nnNXEfhcEW4vs5HH9rN2nyZBWHJE7dPSh7RuX1hw06yIb\n9/BXUS96v0NIGa/Uun0RBC/ZOUFwu10Xu+IROyMZ0oX2dBAsP9xKdxnEXbsoEFLGK7UnY5cV\nDQYHQbuO5fFrTmmwOR7SVw17xv90RzKkqkGEFAVCyniltjh+aDI42GSnzIzrbwviIb1vl8Rv\neD0Z0s5BhBQJQsp4pbYxfog18q7t9Go8pFl2U/yGxcmQdg4ipEgQUsarfGY71sham1R1bSyk\n+XZp/GxeMqSdgwgpEoSU8Wo00uLkxDUzrkqEtCm7KP6nuwkpAxBSxqvRyBV2fRB/1m5U8lm7\n8+yPQbCyw24hPRTlcvdThJTxajSy4Rg76YIROa2XJUNa2SbvtPMLh8Tv8NUYNNtOvm5ztEve\nDxFSxqvRSLDlshMbd5xY9c6GVaMO7fLT+XbZLoO2/KjFQWURrnf/REgem7swfvknuy/qhYCQ\nfNazwZIgqBh5wJqoFwJC8tkfsjpNu+lUmxb1OkBIfpvV96CCfr+KehUICAmQICRAgJAAAUIC\nBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQI\nCRAgJECAkAABQgIECAkQICRAgJAAgf8HiKT7uoux/J0AAAAASUVORK5CYII=", "text/plain": [ "plot without title" ] }, "metadata": { "image/png": { "height": 420, "width": 420 } }, "output_type": "display_data" } ], "source": [ "plot(height, weight)" ] }, { "cell_type": "markdown", "id": "f6c2f13d", "metadata": {}, "source": [ "#### Most functions contain many default parameters" ] }, { "cell_type": "code", "execution_count": 33, "id": "de2fc532", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAMAAADKOT/pAAAC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AASdAHeZh94AAAcTklEQVR4nO3deWCU1b2H8V8SQNZQBYUIBEGogEpVbFkNUBEQ\nEaiiNOgFxJRFUKt1ueLWVmvdUUttVVoXrtdbbfW2va1gK7aoF0GlgF7cWYQoyL4IJHn/uLMk\nYRDyQpjvnHeOPJ8/Zt7MnHjOCXnMbJlYACBtFvUCgK8DQgIECAkQICRAgJAAAUICBAgJECAk\nQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECA\nkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAA\nAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFC\nAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIE\nCAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJ\nECAkQICQAAFCAgQICRAgJEDAQUiLFgJeWVT77/LMh7TAAM8sqPW3eeZDetV2ZnwOQGinvVrr\nzyEk4CsICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQIKZu8FfUCcKgI\nKYu8aLOiXgIOESFlj12dC1pvjXoRODSElD2mH7m88OaoF4FDQ0hZ44tmDwZP1f846mXgkBBS\n1pjUeVdQ0eeCqJeBQ0JI2WJpnb/GTt/Mmxv1QnAoCClbnHVu4mzcKWURLwSHgpCyxHP1liXO\nS/N/HfFKcCgIKTt82eHayqM7jt4Q6UpwSAgpO9x+zMbKo50dfxTpSnBICCkrbGzcrFuVFvVW\nRb0c1BohZYXdv7hzj+k7ol4Oao2QAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJ\nECAkQICQAAFCAgQICRAgJECAkAABQgIECAkQICRAgJAAAUICBAgJECAkQICQAAFCAgQICRAg\nJECAkAABQgIECAkQICRAgJAAAUICB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ngJAAAUICBAgJECAkQICQAAFCAgQICRAgJEDg/wGYOCGZF7Nn8gAAAABJRU5ErkJggg==", "text/plain": [ "plot without title" ] }, "metadata": { "image/png": { "height": 420, "width": 420 } }, "output_type": "display_data" } ], "source": [ "plot(height, weight, pch=2)" ] }, { "cell_type": "markdown", "id": "3beca799", "metadata": {}, "source": [ "#### Default function arguments can be shown with args" ] }, { "cell_type": "code", "execution_count": 34, "id": "a03fe7dc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
function (x, y = NULL, type = \"p\", xlim = NULL, ylim = NULL, \n",
       "    log = \"\", main = NULL, sub = NULL, xlab = NULL, ylab = NULL, \n",
       "    ann = par(\"ann\"), axes = TRUE, frame.plot = axes, panel.first = NULL, \n",
       "    panel.last = NULL, asp = NA, xgap.axis = NA, ygap.axis = NA, \n",
       "    ...) \n",
       "NULL
" ], "text/latex": [ "\\begin{minted}{r}\n", "function (x, y = NULL, type = \"p\", xlim = NULL, ylim = NULL, \n", " log = \"\", main = NULL, sub = NULL, xlab = NULL, ylab = NULL, \n", " ann = par(\"ann\"), axes = TRUE, frame.plot = axes, panel.first = NULL, \n", " panel.last = NULL, asp = NA, xgap.axis = NA, ygap.axis = NA, \n", " ...) \n", "NULL\n", "\\end{minted}" ], "text/markdown": [ "```r\n", "function (x, y = NULL, type = \"p\", xlim = NULL, ylim = NULL, \n", " log = \"\", main = NULL, sub = NULL, xlab = NULL, ylab = NULL, \n", " ann = par(\"ann\"), axes = TRUE, frame.plot = axes, panel.first = NULL, \n", " panel.last = NULL, asp = NA, xgap.axis = NA, ygap.axis = NA, \n", " ...) \n", "NULL\n", "```" ], "text/plain": [ "function (x, y = NULL, type = \"p\", xlim = NULL, ylim = NULL, \n", " log = \"\", main = NULL, sub = NULL, xlab = NULL, ylab = NULL, \n", " ann = par(\"ann\"), axes = TRUE, frame.plot = axes, panel.first = NULL, \n", " panel.last = NULL, asp = NA, xgap.axis = NA, ygap.axis = NA, \n", " ...) \n", "NULL" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "args(plot.default)" ] }, { "cell_type": "markdown", "id": "87d4c7ee", "metadata": {}, "source": [ "#### All functions in R that belongs to packages have help with examples" ] }, { "cell_type": "code", "execution_count": 35, "id": "6226b10f", "metadata": {}, "outputs": [], "source": [ "?base::plot" ] }, { "cell_type": "markdown", "id": "8a6491dd", "metadata": {}, "source": [ "#### Canvas for plotting is still active until a new plot" ] }, { "cell_type": "code", "execution_count": 36, "id": "c37b7038", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAA0gAAANICAMAAADKOT/pAAAC/VBMVEUAAAABAQECAgIDAwME\nBAQFBQUGBgYHBwcICAgJCQkKCgoLCwsMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUW\nFhYXFxcYGBgZGRkaGhobGxscHBwdHR0eHh4fHx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJyco\nKCgpKSkqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjIzMzM0NDQ1NTU2NjY3Nzc4ODg5OTk6\nOjo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlKSkpLS0tM\nTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVWVlZXV1dYWFhZWVlaWlpbW1tcXFxdXV1e\nXl5fX19gYGBhYWFiYmJjY2NkZGRlZWVmZmZnZ2doaGhpaWlqampra2tsbGxtbW1ubm5vb29w\ncHBxcXFycnJ0dHR1dXV2dnZ3d3d4eHh5eXl6enp7e3t8fHx9fX1+fn5/f3+AgICBgYGCgoKD\ng4OEhISFhYWGhoaHh4eIiIiJiYmKioqLi4uMjIyNjY2Ojo6Pj4+QkJCRkZGSkpKTk5OUlJSV\nlZWWlpaXl5eYmJiZmZmampqbm5ucnJydnZ2enp6fn5+goKChoaGioqKjo6OkpKSlpaWmpqan\np6eoqKipqamqqqqrq6usrKytra2urq6vr6+wsLCxsbGysrKzs7O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bo3\nn1l7pdeDquCZMtNDJxxC8ryZavDXlvWOusqyitUvQ+8oUZdHQrpVvWxZW7qpmcetxI92JhCS\n581UL4beVqVNsKwuvSrt94xIO2SHVJY+0v7TbyMhHVuJkEwgJM+bqdbbD5kTrINqxLO2cWq5\nHdIqdYf9gQ8jIR1diZCMICTPm6kO2A+hRlaqoxbYIb2uHrQ/sD4S0tGVCMkIQvK86iPboUZ2\nqZuPvTcU0lJ1p720OBLS0ZUIyQhC8rxajWQPDb/n4fvCIR0MjLb/9AQheQAheV6tRu5V91v2\nUbtpkaN216q/W9a2HieF9Cej8yYmQvK8Wo3sH6jOumlScsfNkZC2dUq97Lrci+0f+GqtNFcN\n/eUhsyMnIELyvFqNWN8Wntm8143HzmzYPq1dv58uVYXHrfRtfnabPQbnTUyE5GOLVthv/6H+\nYHoQEJKfjUzbaFlVk5vtND0ICMnPSpN63/XgBeou03OAkPzt9TFtcsb+xfQUsAgJEEFIgABC\nAgQQEiCAkAABhAQIICRAACEBAggJEEBIgABCAgQQEiCAkAABhAQIICRAACEBAggJEEBIgABC\nAgQQEiCAkAABhAQIICRAACEBAggJEEBIgABCAgT8fz+HVG0jrAzcAAAAAElFTkSuQmCC", "text/plain": [ "plot without title" ] }, "metadata": { "image/png": { "height": 420, "width": 420 } }, "output_type": "display_data" } ], "source": [ "plot(height, weight)\n", "hh = c(1.65, 1.70, 1.75, 1.80, 1.85, 1.90)\n", "lines(hh, 22.5 * hh^2)" ] }, { "cell_type": "markdown", "id": "caf65b7c", "metadata": {}, "source": [ "#### Factors\n", "Factors are used to handle categorical data." ] }, { "cell_type": "code", "execution_count": 37, "id": "38fa7999", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 0
  2. 3
  3. 2
  4. 2
  5. 1
\n", "\n", "
\n", "\t\n", "\t\tLevels:\n", "\t\n", "\t\n", "\t
  1. '0'
  2. '1'
  3. '2'
  4. '3'
\n", "
" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 0\n", "\\item 3\n", "\\item 2\n", "\\item 2\n", "\\item 1\n", "\\end{enumerate*}\n", "\n", "\\emph{Levels}: \\begin{enumerate*}\n", "\\item '0'\n", "\\item '1'\n", "\\item '2'\n", "\\item '3'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 0\n", "2. 3\n", "3. 2\n", "4. 2\n", "5. 1\n", "\n", "\n", "\n", "**Levels**: 1. '0'\n", "2. '1'\n", "3. '2'\n", "4. '3'\n", "\n", "\n" ], "text/plain": [ "[1] 0 3 2 2 1\n", "Levels: 0 < 1 < 2 < 3" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "pain <- c(0,3,2,2,1)\n", "fpain <- factor(pain,levels=0:3, ordered=TRUE)\n", "fpain" ] }, { "cell_type": "markdown", "id": "300d0d78", "metadata": {}, "source": [ "#### Levels provide correspondence between numerical values and categorical labels" ] }, { "cell_type": "code", "execution_count": 38, "id": "9a683e5e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. none
  2. severe
  3. medium
  4. medium
  5. mild
\n", "\n", "
\n", "\t\n", "\t\tLevels:\n", "\t\n", "\t\n", "\t
  1. 'none'
  2. 'mild'
  3. 'medium'
  4. 'severe'
\n", "
" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item none\n", "\\item severe\n", "\\item medium\n", "\\item medium\n", "\\item mild\n", "\\end{enumerate*}\n", "\n", "\\emph{Levels}: \\begin{enumerate*}\n", "\\item 'none'\n", "\\item 'mild'\n", "\\item 'medium'\n", "\\item 'severe'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. none\n", "2. severe\n", "3. medium\n", "4. medium\n", "5. mild\n", "\n", "\n", "\n", "**Levels**: 1. 'none'\n", "2. 'mild'\n", "3. 'medium'\n", "4. 'severe'\n", "\n", "\n" ], "text/plain": [ "[1] none severe medium medium mild \n", "Levels: none < mild < medium < severe" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "levels(fpain) <- c(\"none\",\"mild\",\"medium\",\"severe\")\n", "fpain" ] }, { "cell_type": "markdown", "id": "d019846e", "metadata": {}, "source": [ "#### Convert height to factor\n", "Levels: small, medium, high" ] }, { "cell_type": "markdown", "id": "f1dfffae", "metadata": {}, "source": [ "#### coding setting element by element" ] }, { "cell_type": "code", "execution_count": 39, "id": "07d36349", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. medium
  2. medium
  3. short
  4. tall
  5. medium
  6. tall
\n", "\n", "
\n", "\t\n", "\t\tLevels:\n", "\t\n", "\t\n", "\t
  1. 'medium'
  2. 'short'
  3. 'tall'
\n", "
" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item medium\n", "\\item medium\n", "\\item short\n", "\\item tall\n", "\\item medium\n", "\\item tall\n", "\\end{enumerate*}\n", "\n", "\\emph{Levels}: \\begin{enumerate*}\n", "\\item 'medium'\n", "\\item 'short'\n", "\\item 'tall'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. medium\n", "2. medium\n", "3. short\n", "4. tall\n", "5. medium\n", "6. tall\n", "\n", "\n", "\n", "**Levels**: 1. 'medium'\n", "2. 'short'\n", "3. 'tall'\n", "\n", "\n" ], "text/plain": [ "[1] medium medium short tall medium tall \n", "Levels: medium short tall" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lev <- rep(\"\", length(height))\n", "\n", "for (i in 1:length(height)) {\n", " if (height[i] < 1.7)\n", " lev[i] <- \"short\"\n", " else if (height[i] < 1.9)\n", " lev[i] <- \"medium\"\n", " else \n", " lev[i] <- \"tall\"\n", "}\n", "lev <- as.factor(lev)\n", "lev" ] }, { "cell_type": "markdown", "id": "569660bc", "metadata": {}, "source": [ "#### coding setting the vector at once\n", "It uses the cut function." ] }, { "cell_type": "code", "execution_count": 40, "id": "d81b0ae6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. (1.7,1.9]
  2. (1.7,1.9]
  3. (0,1.7]
  4. (1.7,1.9]
  5. (1.7,1.9]
  6. (1.9,1.8e+308]
\n", "\n", "
\n", "\t\n", "\t\tLevels:\n", "\t\n", "\t\n", "\t
  1. '(0,1.7]'
  2. '(1.7,1.9]'
  3. '(1.9,1.8e+308]'
\n", "
" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item (1.7,1.9{]}\n", "\\item (1.7,1.9{]}\n", "\\item (0,1.7{]}\n", "\\item (1.7,1.9{]}\n", "\\item (1.7,1.9{]}\n", "\\item (1.9,1.8e+308{]}\n", "\\end{enumerate*}\n", "\n", "\\emph{Levels}: \\begin{enumerate*}\n", "\\item '(0,1.7{]}'\n", "\\item '(1.7,1.9{]}'\n", "\\item '(1.9,1.8e+308{]}'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. (1.7,1.9]\n", "2. (1.7,1.9]\n", "3. (0,1.7]\n", "4. (1.7,1.9]\n", "5. (1.7,1.9]\n", "6. (1.9,1.8e+308]\n", "\n", "\n", "\n", "**Levels**: 1. '(0,1.7]'\n", "2. '(1.7,1.9]'\n", "3. '(1.9,1.8e+308]'\n", "\n", "\n" ], "text/plain": [ "[1] (1.7,1.9] (1.7,1.9] (0,1.7] (1.7,1.9] (1.7,1.9] \n", "[6] (1.9,1.8e+308]\n", "Levels: (0,1.7] < (1.7,1.9] < (1.9,1.8e+308]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
  1. medium
  2. medium
  3. short
  4. medium
  5. medium
  6. tall
\n", "\n", "
\n", "\t\n", "\t\tLevels:\n", "\t\n", "\t\n", "\t
  1. 'short'
  2. 'medium'
  3. 'tall'
\n", "
" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item medium\n", "\\item medium\n", "\\item short\n", "\\item medium\n", "\\item medium\n", "\\item tall\n", "\\end{enumerate*}\n", "\n", "\\emph{Levels}: \\begin{enumerate*}\n", "\\item 'short'\n", "\\item 'medium'\n", "\\item 'tall'\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. medium\n", "2. medium\n", "3. short\n", "4. medium\n", "5. medium\n", "6. tall\n", "\n", "\n", "\n", "**Levels**: 1. 'short'\n", "2. 'medium'\n", "3. 'tall'\n", "\n", "\n" ], "text/plain": [ "[1] medium medium short medium medium tall \n", "Levels: short < medium < tall" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lev <- cut(height, breaks=c(0, 1.7, 1.9, .Machine$double.xmax), ordered=TRUE)\n", "lev\n", "levels(lev) <- c(\"short\", \"medium\", \"tall\")\n", "lev" ] }, { "cell_type": "markdown", "id": "a7b75411", "metadata": {}, "source": [ "#### Matrix\n", "Matrices can be filled from vectors or data frames. " ] }, { "cell_type": "code", "execution_count": 41, "id": "d900a570", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 1\n", "\\item 2\n", "\\item 3\n", "\\item 4\n", "\\item 5\n", "\\item 6\n", "\\item 7\n", "\\item 8\n", "\\item 9\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 1\n", "2. 2\n", "3. 3\n", "4. 4\n", "5. 5\n", "6. 6\n", "7. 7\n", "8. 8\n", "9. 9\n", "\n", "\n" ], "text/plain": [ "[1] 1 2 3 4 5 6 7 8 9" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x <- 1:9\n", "x" ] }, { "cell_type": "markdown", "id": "fab3bf6e", "metadata": {}, "source": [ "#### Converting a vector to matrix" ] }, { "cell_type": "code", "execution_count": 42, "id": "36dd40b8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 3 × 3 of type int
147
258
369
\n" ], "text/latex": [ "A matrix: 3 × 3 of type int\n", "\\begin{tabular}{lll}\n", "\t 1 & 4 & 7\\\\\n", "\t 2 & 5 & 8\\\\\n", "\t 3 & 6 & 9\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 3 × 3 of type int\n", "\n", "| 1 | 4 | 7 |\n", "| 2 | 5 | 8 |\n", "| 3 | 6 | 9 |\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 1 4 7 \n", "[2,] 2 5 8 \n", "[3,] 3 6 9 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dim(x) <- c(3,3)\n", "x" ] }, { "cell_type": "markdown", "id": "013a9fa5", "metadata": {}, "source": [ "#### accessing elements from a matrix" ] }, { "cell_type": "code", "execution_count": 43, "id": "31aad9ff", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1] 1\n", "[1] 4\n", "[1] 7\n", "[1] 2\n", "[1] 5\n", "[1] 8\n", "[1] 3\n", "[1] 6\n", "[1] 9\n" ] } ], "source": [ "for (i in 1:nrow(x)) \n", " for (j in 1:ncol(x))\n", " print(x[i,j])\n", " \n" ] }, { "cell_type": "markdown", "id": "582a8811", "metadata": {}, "source": [ "#### Iterating and assigning values to each element" ] }, { "cell_type": "code", "execution_count": 44, "id": "ad2239bd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 3 × 3 of type dbl
31221
61524
91827
\n" ], "text/latex": [ "A matrix: 3 × 3 of type dbl\n", "\\begin{tabular}{lll}\n", "\t 3 & 12 & 21\\\\\n", "\t 6 & 15 & 24\\\\\n", "\t 9 & 18 & 27\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 3 × 3 of type dbl\n", "\n", "| 3 | 12 | 21 |\n", "| 6 | 15 | 24 |\n", "| 9 | 18 | 27 |\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 3 12 21 \n", "[2,] 6 15 24 \n", "[3,] 9 18 27 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "y <- x\n", "for (i in 1:nrow(y)) \n", " for (j in 1:ncol(y))\n", " y[i,j] <- 3 * y[i, j]\n", " \n", "y" ] }, { "cell_type": "markdown", "id": "ea7e0255", "metadata": {}, "source": [ "#### Assigning the values of a matrix at once" ] }, { "cell_type": "code", "execution_count": 45, "id": "a6c41f00", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 3 × 3 of type dbl
31221
61524
91827
\n" ], "text/latex": [ "A matrix: 3 × 3 of type dbl\n", "\\begin{tabular}{lll}\n", "\t 3 & 12 & 21\\\\\n", "\t 6 & 15 & 24\\\\\n", "\t 9 & 18 & 27\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 3 × 3 of type dbl\n", "\n", "| 3 | 12 | 21 |\n", "| 6 | 15 | 24 |\n", "| 9 | 18 | 27 |\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 3 12 21 \n", "[2,] 6 15 24 \n", "[3,] 9 18 27 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "y <- 3*x\n", "y" ] }, { "cell_type": "markdown", "id": "e4503b07", "metadata": {}, "source": [ "#### Converting a vector to a matrix by row" ] }, { "cell_type": "code", "execution_count": 46, "id": "6c1a2c28", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 3 × 3 of type int
123
456
789
\n" ], "text/latex": [ "A matrix: 3 × 3 of type int\n", "\\begin{tabular}{lll}\n", "\t 1 & 2 & 3\\\\\n", "\t 4 & 5 & 6\\\\\n", "\t 7 & 8 & 9\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 3 × 3 of type int\n", "\n", "| 1 | 2 | 3 |\n", "| 4 | 5 | 6 |\n", "| 7 | 8 | 9 |\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 1 2 3 \n", "[2,] 4 5 6 \n", "[3,] 7 8 9 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x <- matrix(1:9,nrow=3,byrow=T)\n", "x" ] }, { "cell_type": "markdown", "id": "2f8b5706", "metadata": {}, "source": [ "#### transposing a matrix" ] }, { "cell_type": "code", "execution_count": 47, "id": "2b2d54df", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A matrix: 3 × 3 of type int
147
258
369
\n" ], "text/latex": [ "A matrix: 3 × 3 of type int\n", "\\begin{tabular}{lll}\n", "\t 1 & 4 & 7\\\\\n", "\t 2 & 5 & 8\\\\\n", "\t 3 & 6 & 9\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A matrix: 3 × 3 of type int\n", "\n", "| 1 | 4 | 7 |\n", "| 2 | 5 | 8 |\n", "| 3 | 6 | 9 |\n", "\n" ], "text/plain": [ " [,1] [,2] [,3]\n", "[1,] 1 4 7 \n", "[2,] 2 5 8 \n", "[3,] 3 6 9 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "x <- t(x)\n", "x" ] }, { "cell_type": "markdown", "id": "4eb25f6b", "metadata": {}, "source": [ "#### computing the determinant of a matrix" ] }, { "cell_type": "code", "execution_count": 48, "id": "10b6b6fa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "0" ], "text/latex": [ "0" ], "text/markdown": [ "0" ], "text/plain": [ "[1] 0" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "det(x)" ] }, { "cell_type": "markdown", "id": "a8dd0d35", "metadata": {}, "source": [ "#### Lists\n", "Lists are used to work with \"objects\"" ] }, { "cell_type": "code", "execution_count": 49, "id": "354a54cd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. \n", "
    1. 5260
    2. 5470
    3. 5640
    4. 6180
    5. 6390
    6. 6515
    7. 6805
    8. 7515
    9. 7515
    10. 8230
    11. 8770
    \n", "
  2. \n", "\t
  3. \n", "
    1. 3910
    2. 4220
    3. 3885
    4. 5160
    5. 5645
    6. 4680
    7. 5265
    8. 5975
    9. 6790
    10. 6900
    11. 7335
    \n", "
  4. \n", "\t
  5. 0
  6. \n", "\t
  7. 'a'
  8. \n", "
\n" ], "text/latex": [ "\\begin{enumerate}\n", "\\item \\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n", "\n", "\\item \\begin{enumerate*}\n", "\\item 3910\n", "\\item 4220\n", "\\item 3885\n", "\\item 5160\n", "\\item 5645\n", "\\item 4680\n", "\\item 5265\n", "\\item 5975\n", "\\item 6790\n", "\\item 6900\n", "\\item 7335\n", "\\end{enumerate*}\n", "\n", "\\item 0\n", "\\item 'a'\n", "\\end{enumerate}\n" ], "text/markdown": [ "1. 1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n", "\n", "2. 1. 3910\n", "2. 4220\n", "3. 3885\n", "4. 5160\n", "5. 5645\n", "6. 4680\n", "7. 5265\n", "8. 5975\n", "9. 6790\n", "10. 6900\n", "11. 7335\n", "\n", "\n", "\n", "3. 0\n", "4. 'a'\n", "\n", "\n" ], "text/plain": [ "[[1]]\n", " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770\n", "\n", "[[2]]\n", " [1] 3910 4220 3885 5160 5645 4680 5265 5975 6790 6900 7335\n", "\n", "[[3]]\n", "[1] 0\n", "\n", "[[4]]\n", "[1] \"a\"\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "a <- c(5260,5470,5640,6180,6390,6515,6805,7515,7515,8230,8770)\n", "b <- c(3910,4220,3885,5160,5645,4680,5265,5975,6790,6900,7335)\n", "\n", "mybag <- list(a, b, 0, \"a\")\n", "mybag" ] }, { "cell_type": "markdown", "id": "ff6d8a47", "metadata": {}, "source": [ "adding an element into a list" ] }, { "cell_type": "code", "execution_count": 50, "id": "5c17f943", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. \n", "
    1. 5260
    2. 5470
    3. 5640
    4. 6180
    5. 6390
    6. 6515
    7. 6805
    8. 7515
    9. 7515
    10. 8230
    11. 8770
    \n", "
  2. \n", "\t
  3. \n", "
    1. 3910
    2. 4220
    3. 3885
    4. 5160
    5. 5645
    6. 4680
    7. 5265
    8. 5975
    9. 6790
    10. 6900
    11. 7335
    \n", "
  4. \n", "\t
  5. 0
  6. \n", "\t
  7. 'a'
  8. \n", "\t
  9. 'b'
  10. \n", "
\n" ], "text/latex": [ "\\begin{enumerate}\n", "\\item \\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n", "\n", "\\item \\begin{enumerate*}\n", "\\item 3910\n", "\\item 4220\n", "\\item 3885\n", "\\item 5160\n", "\\item 5645\n", "\\item 4680\n", "\\item 5265\n", "\\item 5975\n", "\\item 6790\n", "\\item 6900\n", "\\item 7335\n", "\\end{enumerate*}\n", "\n", "\\item 0\n", "\\item 'a'\n", "\\item 'b'\n", "\\end{enumerate}\n" ], "text/markdown": [ "1. 1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n", "\n", "2. 1. 3910\n", "2. 4220\n", "3. 3885\n", "4. 5160\n", "5. 5645\n", "6. 4680\n", "7. 5265\n", "8. 5975\n", "9. 6790\n", "10. 6900\n", "11. 7335\n", "\n", "\n", "\n", "3. 0\n", "4. 'a'\n", "5. 'b'\n", "\n", "\n" ], "text/plain": [ "[[1]]\n", " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770\n", "\n", "[[2]]\n", " [1] 3910 4220 3885 5160 5645 4680 5265 5975 6790 6900 7335\n", "\n", "[[3]]\n", "[1] 0\n", "\n", "[[4]]\n", "[1] \"a\"\n", "\n", "[[5]]\n", "[1] \"b\"\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "n <- length(mybag)\n", "mybag[[n+1]] <- \"b\"\n", "mybag" ] }, { "cell_type": "markdown", "id": "99098b73", "metadata": {}, "source": [ "#### List slicing" ] }, { "cell_type": "code", "execution_count": 51, "id": "8fd47b0b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. \n", "
    1. 5260
    2. 5470
    3. 5640
    4. 6180
    5. 6390
    6. 6515
    7. 6805
    8. 7515
    9. 7515
    10. 8230
    11. 8770
    \n", "
  2. \n", "
\n" ], "text/latex": [ "\\begin{enumerate}\n", "\\item \\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n", "\n", "\\end{enumerate}\n" ], "text/markdown": [ "1. 1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "[[1]]\n", " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "slice <- mybag[1]\n", "slice\n", "is.list(slice)" ] }, { "cell_type": "markdown", "id": "ec157ec8", "metadata": {}, "source": [ "#### Slicing is also a list" ] }, { "cell_type": "code", "execution_count": 52, "id": "946d60f4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
    \n", "\t
  1. \n", "
    1. 5260
    2. 5470
    3. 5640
    4. 6180
    5. 6390
    6. 6515
    7. 6805
    8. 7515
    9. 7515
    10. 8230
    11. 8770
    \n", "
  2. \n", "\t
  3. 0
  4. \n", "
\n" ], "text/latex": [ "\\begin{enumerate}\n", "\\item \\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n", "\n", "\\item 0\n", "\\end{enumerate}\n" ], "text/markdown": [ "1. 1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n", "\n", "2. 0\n", "\n", "\n" ], "text/plain": [ "[[1]]\n", " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770\n", "\n", "[[2]]\n", "[1] 0\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "slice <- mybag[c(1,3)]\n", "slice\n", "is.list(slice)" ] }, { "cell_type": "markdown", "id": "125f81e9", "metadata": {}, "source": [ "#### A list is also a vector" ] }, { "cell_type": "code", "execution_count": 53, "id": "090c69db", "metadata": {}, "outputs": [ { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#list is also a vector\n", "is.vector(slice)" ] }, { "cell_type": "markdown", "id": "bdb0082f", "metadata": {}, "source": [ "#### Member reference\n", "It accesses the element" ] }, { "cell_type": "code", "execution_count": 54, "id": "e7651d67", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 5260
  2. 5470
  3. 5640
  4. 6180
  5. 6390
  6. 6515
  7. 6805
  8. 7515
  9. 7515
  10. 8230
  11. 8770
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n" ], "text/plain": [ " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "h <- mybag[[1]]\n", "h" ] }, { "cell_type": "markdown", "id": "aa046dc8", "metadata": {}, "source": [ "An element can be evaluated. \n", "In this case, it is a vector." ] }, { "cell_type": "code", "execution_count": 55, "id": "95eda4bb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "TRUE" ], "text/latex": [ "TRUE" ], "text/markdown": [ "TRUE" ], "text/plain": [ "[1] TRUE" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "FALSE" ], "text/latex": [ "FALSE" ], "text/markdown": [ "FALSE" ], "text/plain": [ "[1] FALSE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "is.vector(h)\n", "is.list(h)" ] }, { "cell_type": "markdown", "id": "38a8fabf", "metadata": {}, "source": [ "#### Naming variables\n", "They are properties on the list" ] }, { "cell_type": "code", "execution_count": 56, "id": "4da009f5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\t
$x
\n", "\t\t
\n", "
  1. 5260
  2. 5470
  3. 5640
  4. 6180
  5. 6390
  6. 6515
  7. 6805
  8. 7515
  9. 7515
  10. 8230
  11. 8770
\n", "
\n", "\t
$y
\n", "\t\t
\n", "
  1. 3910
  2. 4220
  3. 3885
  4. 5160
  5. 5645
  6. 4680
  7. 5265
  8. 5975
  9. 6790
  10. 6900
  11. 7335
\n", "
\n", "\t
$const
\n", "\t\t
0
\n", "\t
$lit
\n", "\t\t
'a'
\n", "
\n" ], "text/latex": [ "\\begin{description}\n", "\\item[\\$x] \\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n", "\n", "\\item[\\$y] \\begin{enumerate*}\n", "\\item 3910\n", "\\item 4220\n", "\\item 3885\n", "\\item 5160\n", "\\item 5645\n", "\\item 4680\n", "\\item 5265\n", "\\item 5975\n", "\\item 6790\n", "\\item 6900\n", "\\item 7335\n", "\\end{enumerate*}\n", "\n", "\\item[\\$const] 0\n", "\\item[\\$lit] 'a'\n", "\\end{description}\n" ], "text/markdown": [ "$x\n", ": 1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n", "\n", "$y\n", ": 1. 3910\n", "2. 4220\n", "3. 3885\n", "4. 5160\n", "5. 5645\n", "6. 4680\n", "7. 5265\n", "8. 5975\n", "9. 6790\n", "10. 6900\n", "11. 7335\n", "\n", "\n", "\n", "$const\n", ": 0\n", "$lit\n", ": 'a'\n", "\n", "\n" ], "text/plain": [ "$x\n", " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770\n", "\n", "$y\n", " [1] 3910 4220 3885 5160 5645 4680 5265 5975 6790 6900 7335\n", "\n", "$const\n", "[1] 0\n", "\n", "$lit\n", "[1] \"a\"\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mybag <- list(x=a, y=b, const=0, lit=\"a\")\n", "mybag" ] }, { "cell_type": "markdown", "id": "4d0f3795", "metadata": {}, "source": [ "#### Adding, accessing, and removing elements" ] }, { "cell_type": "code", "execution_count": 57, "id": "e75716c3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\t
$x
\n", "\t\t
\n", "
  1. 5260
  2. 5470
  3. 5640
  4. 6180
  5. 6390
  6. 6515
  7. 6805
  8. 7515
  9. 7515
  10. 8230
  11. 8770
\n", "
\n", "\t
$y
\n", "\t\t
\n", "
  1. 3910
  2. 4220
  3. 3885
  4. 5160
  5. 5645
  6. 4680
  7. 5265
  8. 5975
  9. 6790
  10. 6900
  11. 7335
\n", "
\n", "\t
$c
\n", "\t\t
\n", "
  1. 1350
  2. 1250
  3. 1755
  4. 1020
  5. 745
  6. 1835
  7. 1540
  8. 1540
  9. 725
  10. 1330
  11. 1435
\n", "
\n", "
\n" ], "text/latex": [ "\\begin{description}\n", "\\item[\\$x] \\begin{enumerate*}\n", "\\item 5260\n", "\\item 5470\n", "\\item 5640\n", "\\item 6180\n", "\\item 6390\n", "\\item 6515\n", "\\item 6805\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n", "\n", "\\item[\\$y] \\begin{enumerate*}\n", "\\item 3910\n", "\\item 4220\n", "\\item 3885\n", "\\item 5160\n", "\\item 5645\n", "\\item 4680\n", "\\item 5265\n", "\\item 5975\n", "\\item 6790\n", "\\item 6900\n", "\\item 7335\n", "\\end{enumerate*}\n", "\n", "\\item[\\$c] \\begin{enumerate*}\n", "\\item 1350\n", "\\item 1250\n", "\\item 1755\n", "\\item 1020\n", "\\item 745\n", "\\item 1835\n", "\\item 1540\n", "\\item 1540\n", "\\item 725\n", "\\item 1330\n", "\\item 1435\n", "\\end{enumerate*}\n", "\n", "\\end{description}\n" ], "text/markdown": [ "$x\n", ": 1. 5260\n", "2. 5470\n", "3. 5640\n", "4. 6180\n", "5. 6390\n", "6. 6515\n", "7. 6805\n", "8. 7515\n", "9. 7515\n", "10. 8230\n", "11. 8770\n", "\n", "\n", "\n", "$y\n", ": 1. 3910\n", "2. 4220\n", "3. 3885\n", "4. 5160\n", "5. 5645\n", "6. 4680\n", "7. 5265\n", "8. 5975\n", "9. 6790\n", "10. 6900\n", "11. 7335\n", "\n", "\n", "\n", "$c\n", ": 1. 1350\n", "2. 1250\n", "3. 1755\n", "4. 1020\n", "5. 745\n", "6. 1835\n", "7. 1540\n", "8. 1540\n", "9. 725\n", "10. 1330\n", "11. 1435\n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "$x\n", " [1] 5260 5470 5640 6180 6390 6515 6805 7515 7515 8230 8770\n", "\n", "$y\n", " [1] 3910 4220 3885 5160 5645 4680 5265 5975 6790 6900 7335\n", "\n", "$c\n", " [1] 1350 1250 1755 1020 745 1835 1540 1540 725 1330 1435\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mybag$c <- mybag$x - mybag$y\n", "mybag$const <- NULL\n", "mybag$lit <- NULL\n", "mybag" ] }, { "cell_type": "markdown", "id": "414be0df", "metadata": {}, "source": [ "#### Data frames\n", "Data frames (tables) provide support for structured data. " ] }, { "cell_type": "code", "execution_count": 58, "id": "c3e56d5d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 2
AB
<dbl><dbl>
152603910
254704220
356403885
461805160
563905645
665154680
\n" ], "text/latex": [ "A data.frame: 6 × 2\n", "\\begin{tabular}{r|ll}\n", " & A & B\\\\\n", " & & \\\\\n", "\\hline\n", "\t1 & 5260 & 3910\\\\\n", "\t2 & 5470 & 4220\\\\\n", "\t3 & 5640 & 3885\\\\\n", "\t4 & 6180 & 5160\\\\\n", "\t5 & 6390 & 5645\\\\\n", "\t6 & 6515 & 4680\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 2\n", "\n", "| | A <dbl> | B <dbl> |\n", "|---|---|---|\n", "| 1 | 5260 | 3910 |\n", "| 2 | 5470 | 4220 |\n", "| 3 | 5640 | 3885 |\n", "| 4 | 6180 | 5160 |\n", "| 5 | 6390 | 5645 |\n", "| 6 | 6515 | 4680 |\n", "\n" ], "text/plain": [ " A B \n", "1 5260 3910\n", "2 5470 4220\n", "3 5640 3885\n", "4 6180 5160\n", "5 6390 5645\n", "6 6515 4680" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "d <- data.frame(A=a, B=b)\n", "head(d)" ] }, { "cell_type": "markdown", "id": "cf05166f", "metadata": {}, "source": [ "#### Adding a column in the data frame " ] }, { "cell_type": "code", "execution_count": 59, "id": "8d526668", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 3
ABc
<dbl><dbl><dbl>
152603910 9170
254704220 9690
356403885 9525
46180516011340
56390564512035
66515468011195
\n" ], "text/latex": [ "A data.frame: 6 × 3\n", "\\begin{tabular}{r|lll}\n", " & A & B & c\\\\\n", " & & & \\\\\n", "\\hline\n", "\t1 & 5260 & 3910 & 9170\\\\\n", "\t2 & 5470 & 4220 & 9690\\\\\n", "\t3 & 5640 & 3885 & 9525\\\\\n", "\t4 & 6180 & 5160 & 11340\\\\\n", "\t5 & 6390 & 5645 & 12035\\\\\n", "\t6 & 6515 & 4680 & 11195\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 3\n", "\n", "| | A <dbl> | B <dbl> | c <dbl> |\n", "|---|---|---|---|\n", "| 1 | 5260 | 3910 | 9170 |\n", "| 2 | 5470 | 4220 | 9690 |\n", "| 3 | 5640 | 3885 | 9525 |\n", "| 4 | 6180 | 5160 | 11340 |\n", "| 5 | 6390 | 5645 | 12035 |\n", "| 6 | 6515 | 4680 | 11195 |\n", "\n" ], "text/plain": [ " A B c \n", "1 5260 3910 9170\n", "2 5470 4220 9690\n", "3 5640 3885 9525\n", "4 6180 5160 11340\n", "5 6390 5645 12035\n", "6 6515 4680 11195" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "d$c <- d$A + d$B\n", "head(d)" ] }, { "cell_type": "code", "execution_count": 60, "id": "ed285c21", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 2
Bc
<dbl><dbl>
13910 9170
24220 9690
33885 9525
4516011340
5564512035
6468011195
\n" ], "text/latex": [ "A data.frame: 6 × 2\n", "\\begin{tabular}{r|ll}\n", " & B & c\\\\\n", " & & \\\\\n", "\\hline\n", "\t1 & 3910 & 9170\\\\\n", "\t2 & 4220 & 9690\\\\\n", "\t3 & 3885 & 9525\\\\\n", "\t4 & 5160 & 11340\\\\\n", "\t5 & 5645 & 12035\\\\\n", "\t6 & 4680 & 11195\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 2\n", "\n", "| | B <dbl> | c <dbl> |\n", "|---|---|---|\n", "| 1 | 3910 | 9170 |\n", "| 2 | 4220 | 9690 |\n", "| 3 | 3885 | 9525 |\n", "| 4 | 5160 | 11340 |\n", "| 5 | 5645 | 12035 |\n", "| 6 | 4680 | 11195 |\n", "\n" ], "text/plain": [ " B c \n", "1 3910 9170\n", "2 4220 9690\n", "3 3885 9525\n", "4 5160 11340\n", "5 5645 12035\n", "6 4680 11195" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "d$A <- NULL\n", "head(d)" ] }, { "cell_type": "markdown", "id": "b3c2ac80", "metadata": {}, "source": [ "#### Reading csv file\n", "There are many functions for reading CSV, Excel, and RData formats." ] }, { "cell_type": "code", "execution_count": 61, "id": "cb4df166", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 14
TypeAlcoholMalicAshAlcalinityMagnesiumPhenolsFlavanoidsNonflavanoidsProanthocyaninsColorHueDilutionProline
<int><dbl><dbl><dbl><dbl><int><dbl><dbl><dbl><dbl><dbl><dbl><dbl><int>
1113.201.782.1411.21002.652.760.261.284.381.053.401050
2113.162.362.6718.61012.803.240.302.815.681.033.171185
3114.371.952.5016.81133.853.490.242.187.800.863.451480
4113.242.592.8721.01182.802.690.391.824.321.042.93 735
5114.201.762.4515.21123.273.390.341.976.751.052.851450
6114.391.872.4514.6 962.502.520.301.985.251.023.581290
\n" ], "text/latex": [ "A data.frame: 6 × 14\n", "\\begin{tabular}{r|llllllllllllll}\n", " & Type & Alcohol & Malic & Ash & Alcalinity & Magnesium & Phenols & Flavanoids & Nonflavanoids & Proanthocyanins & Color & Hue & Dilution & Proline\\\\\n", " & & & & & & & & & & & & & & \\\\\n", "\\hline\n", "\t1 & 1 & 13.20 & 1.78 & 2.14 & 11.2 & 100 & 2.65 & 2.76 & 0.26 & 1.28 & 4.38 & 1.05 & 3.40 & 1050\\\\\n", "\t2 & 1 & 13.16 & 2.36 & 2.67 & 18.6 & 101 & 2.80 & 3.24 & 0.30 & 2.81 & 5.68 & 1.03 & 3.17 & 1185\\\\\n", "\t3 & 1 & 14.37 & 1.95 & 2.50 & 16.8 & 113 & 3.85 & 3.49 & 0.24 & 2.18 & 7.80 & 0.86 & 3.45 & 1480\\\\\n", "\t4 & 1 & 13.24 & 2.59 & 2.87 & 21.0 & 118 & 2.80 & 2.69 & 0.39 & 1.82 & 4.32 & 1.04 & 2.93 & 735\\\\\n", "\t5 & 1 & 14.20 & 1.76 & 2.45 & 15.2 & 112 & 3.27 & 3.39 & 0.34 & 1.97 & 6.75 & 1.05 & 2.85 & 1450\\\\\n", "\t6 & 1 & 14.39 & 1.87 & 2.45 & 14.6 & 96 & 2.50 & 2.52 & 0.30 & 1.98 & 5.25 & 1.02 & 3.58 & 1290\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 14\n", "\n", "| | Type <int> | Alcohol <dbl> | Malic <dbl> | Ash <dbl> | Alcalinity <dbl> | Magnesium <int> | Phenols <dbl> | Flavanoids <dbl> | Nonflavanoids <dbl> | Proanthocyanins <dbl> | Color <dbl> | Hue <dbl> | Dilution <dbl> | Proline <int> |\n", "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n", "| 1 | 1 | 13.20 | 1.78 | 2.14 | 11.2 | 100 | 2.65 | 2.76 | 0.26 | 1.28 | 4.38 | 1.05 | 3.40 | 1050 |\n", "| 2 | 1 | 13.16 | 2.36 | 2.67 | 18.6 | 101 | 2.80 | 3.24 | 0.30 | 2.81 | 5.68 | 1.03 | 3.17 | 1185 |\n", "| 3 | 1 | 14.37 | 1.95 | 2.50 | 16.8 | 113 | 3.85 | 3.49 | 0.24 | 2.18 | 7.80 | 0.86 | 3.45 | 1480 |\n", "| 4 | 1 | 13.24 | 2.59 | 2.87 | 21.0 | 118 | 2.80 | 2.69 | 0.39 | 1.82 | 4.32 | 1.04 | 2.93 | 735 |\n", "| 5 | 1 | 14.20 | 1.76 | 2.45 | 15.2 | 112 | 3.27 | 3.39 | 0.34 | 1.97 | 6.75 | 1.05 | 2.85 | 1450 |\n", "| 6 | 1 | 14.39 | 1.87 | 2.45 | 14.6 | 96 | 2.50 | 2.52 | 0.30 | 1.98 | 5.25 | 1.02 | 3.58 | 1290 |\n", "\n" ], "text/plain": [ " Type Alcohol Malic Ash Alcalinity Magnesium Phenols Flavanoids Nonflavanoids\n", "1 1 13.20 1.78 2.14 11.2 100 2.65 2.76 0.26 \n", "2 1 13.16 2.36 2.67 18.6 101 2.80 3.24 0.30 \n", "3 1 14.37 1.95 2.50 16.8 113 3.85 3.49 0.24 \n", "4 1 13.24 2.59 2.87 21.0 118 2.80 2.69 0.39 \n", "5 1 14.20 1.76 2.45 15.2 112 3.27 3.39 0.34 \n", "6 1 14.39 1.87 2.45 14.6 96 2.50 2.52 0.30 \n", " Proanthocyanins Color Hue Dilution Proline\n", "1 1.28 4.38 1.05 3.40 1050 \n", "2 2.81 5.68 1.03 3.17 1185 \n", "3 2.18 7.80 0.86 3.45 1480 \n", "4 1.82 4.32 1.04 2.93 735 \n", "5 1.97 6.75 1.05 2.85 1450 \n", "6 1.98 5.25 1.02 3.58 1290 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "wine = read.table(\n", " \"http://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data\", \n", " header = TRUE, sep = \",\")\n", " colnames(wine) <- c('Type', 'Alcohol', 'Malic', 'Ash', \n", " 'Alcalinity', 'Magnesium', 'Phenols', \n", " 'Flavanoids', 'Nonflavanoids',\n", " 'Proanthocyanins', 'Color', 'Hue', \n", " 'Dilution', 'Proline')\n", "head(wine)" ] }, { "cell_type": "markdown", "id": "11892ffc", "metadata": {}, "source": [ "#### saving in binary format " ] }, { "cell_type": "code", "execution_count": 62, "id": "2143afee", "metadata": {}, "outputs": [], "source": [ "save(wine, file=\"wine.RData\")" ] }, { "cell_type": "markdown", "id": "837380f2", "metadata": {}, "source": [ "#### removing data frame from memory" ] }, { "cell_type": "code", "execution_count": 63, "id": "cd5bdb2d", "metadata": {}, "outputs": [], "source": [ "rm(wine)" ] }, { "cell_type": "markdown", "id": "c5b982a0", "metadata": {}, "source": [ "#### load binary format" ] }, { "cell_type": "code", "execution_count": 64, "id": "4bb77c1f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 3 × 14
TypeAlcoholMalicAshAlcalinityMagnesiumPhenolsFlavanoidsNonflavanoidsProanthocyaninsColorHueDilutionProline
<int><dbl><dbl><dbl><dbl><int><dbl><dbl><dbl><dbl><dbl><dbl><dbl><int>
1113.201.782.1411.21002.652.760.261.284.381.053.401050
2113.162.362.6718.61012.803.240.302.815.681.033.171185
3114.371.952.5016.81133.853.490.242.187.800.863.451480
\n" ], "text/latex": [ "A data.frame: 3 × 14\n", "\\begin{tabular}{r|llllllllllllll}\n", " & Type & Alcohol & Malic & Ash & Alcalinity & Magnesium & Phenols & Flavanoids & Nonflavanoids & Proanthocyanins & Color & Hue & Dilution & Proline\\\\\n", " & & & & & & & & & & & & & & \\\\\n", "\\hline\n", "\t1 & 1 & 13.20 & 1.78 & 2.14 & 11.2 & 100 & 2.65 & 2.76 & 0.26 & 1.28 & 4.38 & 1.05 & 3.40 & 1050\\\\\n", "\t2 & 1 & 13.16 & 2.36 & 2.67 & 18.6 & 101 & 2.80 & 3.24 & 0.30 & 2.81 & 5.68 & 1.03 & 3.17 & 1185\\\\\n", "\t3 & 1 & 14.37 & 1.95 & 2.50 & 16.8 & 113 & 3.85 & 3.49 & 0.24 & 2.18 & 7.80 & 0.86 & 3.45 & 1480\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 3 × 14\n", "\n", "| | Type <int> | Alcohol <dbl> | Malic <dbl> | Ash <dbl> | Alcalinity <dbl> | Magnesium <int> | Phenols <dbl> | Flavanoids <dbl> | Nonflavanoids <dbl> | Proanthocyanins <dbl> | Color <dbl> | Hue <dbl> | Dilution <dbl> | Proline <int> |\n", "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n", "| 1 | 1 | 13.20 | 1.78 | 2.14 | 11.2 | 100 | 2.65 | 2.76 | 0.26 | 1.28 | 4.38 | 1.05 | 3.40 | 1050 |\n", "| 2 | 1 | 13.16 | 2.36 | 2.67 | 18.6 | 101 | 2.80 | 3.24 | 0.30 | 2.81 | 5.68 | 1.03 | 3.17 | 1185 |\n", "| 3 | 1 | 14.37 | 1.95 | 2.50 | 16.8 | 113 | 3.85 | 3.49 | 0.24 | 2.18 | 7.80 | 0.86 | 3.45 | 1480 |\n", "\n" ], "text/plain": [ " Type Alcohol Malic Ash Alcalinity Magnesium Phenols Flavanoids Nonflavanoids\n", "1 1 13.20 1.78 2.14 11.2 100 2.65 2.76 0.26 \n", "2 1 13.16 2.36 2.67 18.6 101 2.80 3.24 0.30 \n", "3 1 14.37 1.95 2.50 16.8 113 3.85 3.49 0.24 \n", " Proanthocyanins Color Hue Dilution Proline\n", "1 1.28 4.38 1.05 3.40 1050 \n", "2 2.81 5.68 1.03 3.17 1185 \n", "3 2.18 7.80 0.86 3.45 1480 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "load(\"wine.RData\")\n", "head(wine, 3)" ] }, { "cell_type": "markdown", "id": "dfd0d49f", "metadata": {}, "source": [ "#### exporting data.frame into csv file" ] }, { "cell_type": "code", "execution_count": 65, "id": "99c07fd0", "metadata": {}, "outputs": [], "source": [ "write.table(wine, file=\"wine.csv\", row.names=FALSE, quote = FALSE, sep = \",\")" ] }, { "cell_type": "markdown", "id": "f5147833", "metadata": {}, "source": [ "#### filtering vectors" ] }, { "cell_type": "code", "execution_count": 66, "id": "82575667", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. FALSE
  2. FALSE
  3. FALSE
  4. FALSE
  5. FALSE
  6. FALSE
  7. FALSE
  8. TRUE
  9. TRUE
  10. TRUE
  11. TRUE
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item FALSE\n", "\\item FALSE\n", "\\item FALSE\n", "\\item FALSE\n", "\\item FALSE\n", "\\item FALSE\n", "\\item FALSE\n", "\\item TRUE\n", "\\item TRUE\n", "\\item TRUE\n", "\\item TRUE\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. FALSE\n", "2. FALSE\n", "3. FALSE\n", "4. FALSE\n", "5. FALSE\n", "6. FALSE\n", "7. FALSE\n", "8. TRUE\n", "9. TRUE\n", "10. TRUE\n", "11. TRUE\n", "\n", "\n" ], "text/plain": [ " [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "a <- c(5260,5470,5640,6180,6390,6515,6805,7515,7515,8230,8770)\n", "b <- c(3910,4220,3885,5160,5645,4680,5265,5975,6790,6900,7335)\n", "\n", "# logical vector\n", "bool <- (a > 7000)\n", "bool" ] }, { "cell_type": "code", "execution_count": 67, "id": "a03b1408", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 7515
  2. 7515
  3. 8230
  4. 8770
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 7515\n", "\\item 7515\n", "\\item 8230\n", "\\item 8770\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 7515\n", "2. 7515\n", "3. 8230\n", "4. 8770\n", "\n", "\n" ], "text/plain": [ "[1] 7515 7515 8230 8770" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# selecting elements from positions that are true\n", "a[bool] " ] }, { "cell_type": "code", "execution_count": 68, "id": "20ba5879", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 3910
  2. 4220
  3. 3885
  4. 5975
  5. 6790
  6. 6900
  7. 7335
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 3910\n", "\\item 4220\n", "\\item 3885\n", "\\item 5975\n", "\\item 6790\n", "\\item 6900\n", "\\item 7335\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 3910\n", "2. 4220\n", "3. 3885\n", "4. 5975\n", "5. 6790\n", "6. 6900\n", "7. 7335\n", "\n", "\n" ], "text/plain": [ "[1] 3910 4220 3885 5975 6790 6900 7335" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# filtering with logical expressions\n", "b[a < 6000 | a > 7000]" ] }, { "cell_type": "code", "execution_count": 69, "id": "d976d8c5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 5160
  2. 5645
  3. 4680
  4. 5265
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 5160\n", "\\item 5645\n", "\\item 4680\n", "\\item 5265\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 5160\n", "2. 5645\n", "3. 4680\n", "4. 5265\n", "\n", "\n" ], "text/plain": [ "[1] 5160 5645 4680 5265" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "b[6000 <= a & a <= 7000]" ] }, { "cell_type": "markdown", "id": "8c969809", "metadata": {}, "source": [ "#### filtering data frames" ] }, { "cell_type": "code", "execution_count": 70, "id": "f0175992", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 11 × 3
abc
<dbl><dbl><dbl>
1526039101350
2547042201250
3564038851755
4618051601020
563905645 745
6651546801835
7680552651540
8751559751540
975156790 725
10823069001330
11877073351435
\n" ], "text/latex": [ "A data.frame: 11 × 3\n", "\\begin{tabular}{r|lll}\n", " & a & b & c\\\\\n", " & & & \\\\\n", "\\hline\n", "\t1 & 5260 & 3910 & 1350\\\\\n", "\t2 & 5470 & 4220 & 1250\\\\\n", "\t3 & 5640 & 3885 & 1755\\\\\n", "\t4 & 6180 & 5160 & 1020\\\\\n", "\t5 & 6390 & 5645 & 745\\\\\n", "\t6 & 6515 & 4680 & 1835\\\\\n", "\t7 & 6805 & 5265 & 1540\\\\\n", "\t8 & 7515 & 5975 & 1540\\\\\n", "\t9 & 7515 & 6790 & 725\\\\\n", "\t10 & 8230 & 6900 & 1330\\\\\n", "\t11 & 8770 & 7335 & 1435\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 11 × 3\n", "\n", "| | a <dbl> | b <dbl> | c <dbl> |\n", "|---|---|---|---|\n", "| 1 | 5260 | 3910 | 1350 |\n", "| 2 | 5470 | 4220 | 1250 |\n", "| 3 | 5640 | 3885 | 1755 |\n", "| 4 | 6180 | 5160 | 1020 |\n", "| 5 | 6390 | 5645 | 745 |\n", "| 6 | 6515 | 4680 | 1835 |\n", "| 7 | 6805 | 5265 | 1540 |\n", "| 8 | 7515 | 5975 | 1540 |\n", "| 9 | 7515 | 6790 | 725 |\n", "| 10 | 8230 | 6900 | 1330 |\n", "| 11 | 8770 | 7335 | 1435 |\n", "\n" ], "text/plain": [ " a b c \n", "1 5260 3910 1350\n", "2 5470 4220 1250\n", "3 5640 3885 1755\n", "4 6180 5160 1020\n", "5 6390 5645 745\n", "6 6515 4680 1835\n", "7 6805 5265 1540\n", "8 7515 5975 1540\n", "9 7515 6790 725\n", "10 8230 6900 1330\n", "11 8770 7335 1435" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "data <- data.frame(a=a, b=b)\n", "data$c <- data$a - data$b\n", "head(data, nrow(data))" ] }, { "cell_type": "code", "execution_count": 71, "id": "3f08fc76", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 4 × 3
abc
<dbl><dbl><dbl>
8751559751540
975156790 725
10823069001330
11877073351435
\n" ], "text/latex": [ "A data.frame: 4 × 3\n", "\\begin{tabular}{r|lll}\n", " & a & b & c\\\\\n", " & & & \\\\\n", "\\hline\n", "\t8 & 7515 & 5975 & 1540\\\\\n", "\t9 & 7515 & 6790 & 725\\\\\n", "\t10 & 8230 & 6900 & 1330\\\\\n", "\t11 & 8770 & 7335 & 1435\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 4 × 3\n", "\n", "| | a <dbl> | b <dbl> | c <dbl> |\n", "|---|---|---|---|\n", "| 8 | 7515 | 5975 | 1540 |\n", "| 9 | 7515 | 6790 | 725 |\n", "| 10 | 8230 | 6900 | 1330 |\n", "| 11 | 8770 | 7335 | 1435 |\n", "\n" ], "text/plain": [ " a b c \n", "8 7515 5975 1540\n", "9 7515 6790 725\n", "10 8230 6900 1330\n", "11 8770 7335 1435" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(data[data$a > 7000,])" ] }, { "cell_type": "code", "execution_count": 72, "id": "9bbfd456", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 4 × 2
ab
<dbl><dbl>
875155975
975156790
1082306900
1187707335
\n" ], "text/latex": [ "A data.frame: 4 × 2\n", "\\begin{tabular}{r|ll}\n", " & a & b\\\\\n", " & & \\\\\n", "\\hline\n", "\t8 & 7515 & 5975\\\\\n", "\t9 & 7515 & 6790\\\\\n", "\t10 & 8230 & 6900\\\\\n", "\t11 & 8770 & 7335\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 4 × 2\n", "\n", "| | a <dbl> | b <dbl> |\n", "|---|---|---|\n", "| 8 | 7515 | 5975 |\n", "| 9 | 7515 | 6790 |\n", "| 10 | 8230 | 6900 |\n", "| 11 | 8770 | 7335 |\n", "\n" ], "text/plain": [ " a b \n", "8 7515 5975\n", "9 7515 6790\n", "10 8230 6900\n", "11 8770 7335" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(data[data$a > 7000,c(1,2)])" ] }, { "cell_type": "markdown", "id": "a5454520", "metadata": {}, "source": [ "#### performance with matrix and data frames" ] }, { "cell_type": "code", "execution_count": 73, "id": "cdc8c347", "metadata": {}, "outputs": [], "source": [ "rheight <- rnorm(100000, 1.8, sd=0.2)\n", "rweight <- rnorm(100000, 72, sd=15)" ] }, { "cell_type": "markdown", "id": "f228be75", "metadata": {}, "source": [ "#### computing a entire column at once" ] }, { "cell_type": "code", "execution_count": 74, "id": "dae10733", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Time difference of 0.002118826 secs" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "2400984 bytes" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "start_time <- Sys.time()\n", "hw <- data.frame(height=rheight, weight=rweight)\n", "hw$bmi <- hw$weight/hw$height^2\n", "end_time <- Sys.time()\n", "end_time - start_time\n", "object.size(hw)" ] }, { "cell_type": "markdown", "id": "740b7c7c", "metadata": {}, "source": [ "#### processing cell by cell" ] }, { "cell_type": "code", "execution_count": 75, "id": "f0590ce1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Time difference of 4.172815 secs" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "start_time <- Sys.time()\n", "hw <- data.frame(height=rheight, weight=rweight)\n", "for (i in 1:nrow(hw)) {\n", " hw$bmi[i] <- hw$weight[i]/hw$height[i]^2\n", "}\n", "end_time <- Sys.time()\n", "end_time - start_time" ] }, { "cell_type": "markdown", "id": "feadffd7", "metadata": {}, "source": [ "#### convert the entire column" ] }, { "cell_type": "code", "execution_count": 76, "id": "b5e4b09a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Time difference of 0.14888 secs" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "start_time <- Sys.time()\n", "hw <- data.frame(height=rheight, weight=rweight)\n", "hw <- as.matrix(hw)\n", "hw <- cbind(hw, 0)\n", "for (i in 1:nrow(hw)) {\n", " hw[i,3] <- hw[i,2]/hw[i,1]^2\n", "}\n", "end_time <- Sys.time()\n", "end_time - start_time\n" ] }, { "cell_type": "markdown", "id": "8314bae7", "metadata": {}, "source": [ "#### apply family\n", "\n", "apply functions can be applied for all rows or columns. \n", "\n", "The first character of the function name establishes the return type (s: simple, l: list)." ] }, { "cell_type": "code", "execution_count": 77, "id": "fa3b939a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 2
blood.glucoseshort.velocity
<dbl><dbl>
115.31.76
210.81.34
3 8.11.27
419.51.47
5 7.21.27
6 5.31.49
\n" ], "text/latex": [ "A data.frame: 6 × 2\n", "\\begin{tabular}{r|ll}\n", " & blood.glucose & short.velocity\\\\\n", " & & \\\\\n", "\\hline\n", "\t1 & 15.3 & 1.76\\\\\n", "\t2 & 10.8 & 1.34\\\\\n", "\t3 & 8.1 & 1.27\\\\\n", "\t4 & 19.5 & 1.47\\\\\n", "\t5 & 7.2 & 1.27\\\\\n", "\t6 & 5.3 & 1.49\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 2\n", "\n", "| | blood.glucose <dbl> | short.velocity <dbl> |\n", "|---|---|---|\n", "| 1 | 15.3 | 1.76 |\n", "| 2 | 10.8 | 1.34 |\n", "| 3 | 8.1 | 1.27 |\n", "| 4 | 19.5 | 1.47 |\n", "| 5 | 7.2 | 1.27 |\n", "| 6 | 5.3 | 1.49 |\n", "\n" ], "text/plain": [ " blood.glucose short.velocity\n", "1 15.3 1.76 \n", "2 10.8 1.34 \n", "3 8.1 1.27 \n", "4 19.5 1.47 \n", "5 7.2 1.27 \n", "6 5.3 1.49 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "library(ISwR)\n", "data(thuesen)\n", "head(thuesen)" ] }, { "cell_type": "code", "execution_count": 78, "id": "0a409147", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\t
$blood.glucose
\n", "\t\t
10.3
\n", "\t
$short.velocity
\n", "\t\t
1.32565217391304
\n", "
\n" ], "text/latex": [ "\\begin{description}\n", "\\item[\\$blood.glucose] 10.3\n", "\\item[\\$short.velocity] 1.32565217391304\n", "\\end{description}\n" ], "text/markdown": [ "$blood.glucose\n", ": 10.3\n", "$short.velocity\n", ": 1.32565217391304\n", "\n", "\n" ], "text/plain": [ "$blood.glucose\n", "[1] 10.3\n", "\n", "$short.velocity\n", "[1] 1.325652\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#lapply returns a list\n", "lapply(thuesen, mean, na.rm=T)" ] }, { "cell_type": "code", "execution_count": 79, "id": "37e7c1b7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
blood.glucose
10.3
short.velocity
1.32565217391304
\n" ], "text/latex": [ "\\begin{description*}\n", "\\item[blood.glucose] 10.3\n", "\\item[short.velocity] 1.32565217391304\n", "\\end{description*}\n" ], "text/markdown": [ "blood.glucose\n", ": 10.3short.velocity\n", ": 1.32565217391304\n", "\n" ], "text/plain": [ " blood.glucose short.velocity \n", " 10.300000 1.325652 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#sapply returns a vector\n", "sapply(thuesen, mean, na.rm=T)" ] }, { "cell_type": "code", "execution_count": 80, "id": "a91b1d25", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 1.76
  2. 1.34
  3. 1.27
  4. 1.47
  5. 1.27
  6. 1.49
  7. 1.31
  8. 1.09
  9. 1.18
  10. 1.22
  11. 1.25
  12. 1.19
  13. 1.95
  14. 1.28
  15. 1.52
  16. 8.6
  17. 1.12
  18. 1.37
  19. 1.19
  20. 1.05
  21. 1.32
  22. 1.03
  23. 1.12
  24. 1.7
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 1.76\n", "\\item 1.34\n", "\\item 1.27\n", "\\item 1.47\n", "\\item 1.27\n", "\\item 1.49\n", "\\item 1.31\n", "\\item 1.09\n", "\\item 1.18\n", "\\item 1.22\n", "\\item 1.25\n", "\\item 1.19\n", "\\item 1.95\n", "\\item 1.28\n", "\\item 1.52\n", "\\item 8.6\n", "\\item 1.12\n", "\\item 1.37\n", "\\item 1.19\n", "\\item 1.05\n", "\\item 1.32\n", "\\item 1.03\n", "\\item 1.12\n", "\\item 1.7\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 1.76\n", "2. 1.34\n", "3. 1.27\n", "4. 1.47\n", "5. 1.27\n", "6. 1.49\n", "7. 1.31\n", "8. 1.09\n", "9. 1.18\n", "10. 1.22\n", "11. 1.25\n", "12. 1.19\n", "13. 1.95\n", "14. 1.28\n", "15. 1.52\n", "16. 8.6\n", "17. 1.12\n", "18. 1.37\n", "19. 1.19\n", "20. 1.05\n", "21. 1.32\n", "22. 1.03\n", "23. 1.12\n", "24. 1.7\n", "\n", "\n" ], "text/plain": [ " [1] 1.76 1.34 1.27 1.47 1.27 1.49 1.31 1.09 1.18 1.22 1.25 1.19 1.95 1.28 1.52\n", "[16] 8.60 1.12 1.37 1.19 1.05 1.32 1.03 1.12 1.70" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
blood.glucose
4.2
short.velocity
1.03
\n" ], "text/latex": [ "\\begin{description*}\n", "\\item[blood.glucose] 4.2\n", "\\item[short.velocity] 1.03\n", "\\end{description*}\n" ], "text/markdown": [ "blood.glucose\n", ": 4.2short.velocity\n", ": 1.03\n", "\n" ], "text/plain": [ " blood.glucose short.velocity \n", " 4.20 1.03 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# apply - second parameter (1: by rows, 2: by columns)\n", "m <- as.matrix(thuesen)\n", "apply(m, 1, min, na.rm=TRUE)\n", "apply(m, 2, min, na.rm=TRUE)" ] }, { "cell_type": "markdown", "id": "331fe9d8", "metadata": {}, "source": [ "### sort and order" ] }, { "cell_type": "code", "execution_count": 81, "id": "7be5fb8f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 2
blood.glucoseshort.velocity
<dbl><dbl>
115.31.76
210.81.34
3 8.11.27
419.51.47
5 7.21.27
6 5.31.49
\n" ], "text/latex": [ "A data.frame: 6 × 2\n", "\\begin{tabular}{r|ll}\n", " & blood.glucose & short.velocity\\\\\n", " & & \\\\\n", "\\hline\n", "\t1 & 15.3 & 1.76\\\\\n", "\t2 & 10.8 & 1.34\\\\\n", "\t3 & 8.1 & 1.27\\\\\n", "\t4 & 19.5 & 1.47\\\\\n", "\t5 & 7.2 & 1.27\\\\\n", "\t6 & 5.3 & 1.49\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 2\n", "\n", "| | blood.glucose <dbl> | short.velocity <dbl> |\n", "|---|---|---|\n", "| 1 | 15.3 | 1.76 |\n", "| 2 | 10.8 | 1.34 |\n", "| 3 | 8.1 | 1.27 |\n", "| 4 | 19.5 | 1.47 |\n", "| 5 | 7.2 | 1.27 |\n", "| 6 | 5.3 | 1.49 |\n", "\n" ], "text/plain": [ " blood.glucose short.velocity\n", "1 15.3 1.76 \n", "2 10.8 1.34 \n", "3 8.1 1.27 \n", "4 19.5 1.47 \n", "5 7.2 1.27 \n", "6 5.3 1.49 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "library(ISwR)\n", "data(thuesen)\n", "head(thuesen)" ] }, { "cell_type": "code", "execution_count": 82, "id": "f7f7f7a1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 4.2
  2. 4.9
  3. 5.2
  4. 5.3
  5. 6.7
  6. 6.7
  7. 7.2
  8. 7.5
  9. 8.1
  10. 8.6
  11. 8.8
  12. 9.3
  13. 9.5
  14. 10.3
  15. 10.8
  16. 11.1
  17. 12.2
  18. 12.5
  19. 13.3
  20. 15.1
  21. 15.3
  22. 16.1
  23. 19
  24. 19.5
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 4.2\n", "\\item 4.9\n", "\\item 5.2\n", "\\item 5.3\n", "\\item 6.7\n", "\\item 6.7\n", "\\item 7.2\n", "\\item 7.5\n", "\\item 8.1\n", "\\item 8.6\n", "\\item 8.8\n", "\\item 9.3\n", "\\item 9.5\n", "\\item 10.3\n", "\\item 10.8\n", "\\item 11.1\n", "\\item 12.2\n", "\\item 12.5\n", "\\item 13.3\n", "\\item 15.1\n", "\\item 15.3\n", "\\item 16.1\n", "\\item 19\n", "\\item 19.5\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 4.2\n", "2. 4.9\n", "3. 5.2\n", "4. 5.3\n", "5. 6.7\n", "6. 6.7\n", "7. 7.2\n", "8. 7.5\n", "9. 8.1\n", "10. 8.6\n", "11. 8.8\n", "12. 9.3\n", "13. 9.5\n", "14. 10.3\n", "15. 10.8\n", "16. 11.1\n", "17. 12.2\n", "18. 12.5\n", "19. 13.3\n", "20. 15.1\n", "21. 15.3\n", "22. 16.1\n", "23. 19\n", "24. 19.5\n", "\n", "\n" ], "text/plain": [ " [1] 4.2 4.9 5.2 5.3 6.7 6.7 7.2 7.5 8.1 8.6 8.8 9.3 9.5 10.3 10.8\n", "[16] 11.1 12.2 12.5 13.3 15.1 15.3 16.1 19.0 19.5" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sort(thuesen$blood.glucose)" ] }, { "cell_type": "code", "execution_count": 83, "id": "fa5a3d0e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
  1. 17
  2. 22
  3. 12
  4. 6
  5. 11
  6. 15
  7. 5
  8. 9
  9. 3
  10. 16
  11. 23
  12. 7
  13. 24
  14. 18
  15. 2
  16. 8
  17. 10
  18. 19
  19. 21
  20. 14
  21. 1
  22. 20
  23. 13
  24. 4
\n" ], "text/latex": [ "\\begin{enumerate*}\n", "\\item 17\n", "\\item 22\n", "\\item 12\n", "\\item 6\n", "\\item 11\n", "\\item 15\n", "\\item 5\n", "\\item 9\n", "\\item 3\n", "\\item 16\n", "\\item 23\n", "\\item 7\n", "\\item 24\n", "\\item 18\n", "\\item 2\n", "\\item 8\n", "\\item 10\n", "\\item 19\n", "\\item 21\n", "\\item 14\n", "\\item 1\n", "\\item 20\n", "\\item 13\n", "\\item 4\n", "\\end{enumerate*}\n" ], "text/markdown": [ "1. 17\n", "2. 22\n", "3. 12\n", "4. 6\n", "5. 11\n", "6. 15\n", "7. 5\n", "8. 9\n", "9. 3\n", "10. 16\n", "11. 23\n", "12. 7\n", "13. 24\n", "14. 18\n", "15. 2\n", "16. 8\n", "17. 10\n", "18. 19\n", "19. 21\n", "20. 14\n", "21. 1\n", "22. 20\n", "23. 13\n", "24. 4\n", "\n", "\n" ], "text/plain": [ " [1] 17 22 12 6 11 15 5 9 3 16 23 7 24 18 2 8 10 19 21 14 1 20 13 4" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "order(thuesen$blood.glucose)" ] }, { "cell_type": "code", "execution_count": 84, "id": "ca65c09c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 2
blood.glucoseshort.velocity
<dbl><dbl>
174.21.12
224.91.03
125.21.19
65.31.49
116.71.25
156.71.52
\n" ], "text/latex": [ "A data.frame: 6 × 2\n", "\\begin{tabular}{r|ll}\n", " & blood.glucose & short.velocity\\\\\n", " & & \\\\\n", "\\hline\n", "\t17 & 4.2 & 1.12\\\\\n", "\t22 & 4.9 & 1.03\\\\\n", "\t12 & 5.2 & 1.19\\\\\n", "\t6 & 5.3 & 1.49\\\\\n", "\t11 & 6.7 & 1.25\\\\\n", "\t15 & 6.7 & 1.52\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 2\n", "\n", "| | blood.glucose <dbl> | short.velocity <dbl> |\n", "|---|---|---|\n", "| 17 | 4.2 | 1.12 |\n", "| 22 | 4.9 | 1.03 |\n", "| 12 | 5.2 | 1.19 |\n", "| 6 | 5.3 | 1.49 |\n", "| 11 | 6.7 | 1.25 |\n", "| 15 | 6.7 | 1.52 |\n", "\n" ], "text/plain": [ " blood.glucose short.velocity\n", "17 4.2 1.12 \n", "22 4.9 1.03 \n", "12 5.2 1.19 \n", "6 5.3 1.49 \n", "11 6.7 1.25 \n", "15 6.7 1.52 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "o <- order(thuesen$blood.glucose)\n", "sorted <- thuesen[o,]\n", "head(sorted)" ] }, { "cell_type": "markdown", "id": "b73fab4d", "metadata": {}, "source": [ "#### Pipelines\n", "The operator $\\%$>$\\%$ creates a pipeline. \n", "\n", "The first parameter of the next invoked function receives the data from the pipeline. \n", "\n", "Library $dplyr$ contains a set of functions that support relational algebra operations." ] }, { "cell_type": "code", "execution_count": 85, "id": "30b5e039", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 4
YearQuarterFlightsDelays
<int><int><int><int>
120161116
220162125
320163133
420164125
520171104
620172 93
\n" ], "text/latex": [ "A data.frame: 6 × 4\n", "\\begin{tabular}{r|llll}\n", " & Year & Quarter & Flights & Delays\\\\\n", " & & & & \\\\\n", "\\hline\n", "\t1 & 2016 & 1 & 11 & 6\\\\\n", "\t2 & 2016 & 2 & 12 & 5\\\\\n", "\t3 & 2016 & 3 & 13 & 3\\\\\n", "\t4 & 2016 & 4 & 12 & 5\\\\\n", "\t5 & 2017 & 1 & 10 & 4\\\\\n", "\t6 & 2017 & 2 & 9 & 3\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 4\n", "\n", "| | Year <int> | Quarter <int> | Flights <int> | Delays <int> |\n", "|---|---|---|---|---|\n", "| 1 | 2016 | 1 | 11 | 6 |\n", "| 2 | 2016 | 2 | 12 | 5 |\n", "| 3 | 2016 | 3 | 13 | 3 |\n", "| 4 | 2016 | 4 | 12 | 5 |\n", "| 5 | 2017 | 1 | 10 | 4 |\n", "| 6 | 2017 | 2 | 9 | 3 |\n", "\n" ], "text/plain": [ " Year Quarter Flights Delays\n", "1 2016 1 11 6 \n", "2 2016 2 12 5 \n", "3 2016 3 13 3 \n", "4 2016 4 12 5 \n", "5 2017 1 10 4 \n", "6 2017 2 9 3 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "flight_data <- read.table(text = \"Year Quarter Flights Delays\n", " 2016 1 11 6\n", " 2016 2 12 5\n", " 2016 3 13 3\n", " 2016 4 12 5\n", " 2017 1 10 4\n", " 2017 2 9 3\n", " 2017 3 11 4\n", " 2017 4 25 15\n", " 2018 1 14 3\n", " 2018 2 12 5\n", " 2018 3 13 3\n", " 2018 4 15 4\",\n", " header = TRUE,sep = \"\") \n", "head(flight_data)" ] }, { "cell_type": "code", "execution_count": 86, "id": "5b900bf8", "metadata": {}, "outputs": [], "source": [ "#install.packages(\"dplyr\")" ] }, { "cell_type": "code", "execution_count": 87, "id": "b25f0481", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "Attaching package: ‘dplyr’\n", "\n", "\n", "The following objects are masked from ‘package:stats’:\n", "\n", " filter, lag\n", "\n", "\n", "The following objects are masked from ‘package:base’:\n", "\n", " intersect, setdiff, setequal, union\n", "\n", "\n" ] }, { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\n", "
A data.frame: 2 × 3
YearQuarterFlights
<int><int><int>
12016111
22017425
\n" ], "text/latex": [ "A data.frame: 2 × 3\n", "\\begin{tabular}{r|lll}\n", " & Year & Quarter & Flights\\\\\n", " & & & \\\\\n", "\\hline\n", "\t1 & 2016 & 1 & 11\\\\\n", "\t2 & 2017 & 4 & 25\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 2 × 3\n", "\n", "| | Year <int> | Quarter <int> | Flights <int> |\n", "|---|---|---|---|\n", "| 1 | 2016 | 1 | 11 |\n", "| 2 | 2017 | 4 | 25 |\n", "\n" ], "text/plain": [ " Year Quarter Flights\n", "1 2016 1 11 \n", "2 2017 4 25 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "library(dplyr)\n", "result <- flight_data %>% \n", " filter(Delays > 5) %>% \n", " select(Year, Quarter, Flights)\n", "head(result)" ] }, { "cell_type": "code", "execution_count": 88, "id": "eddf7163", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\n", "
A tibble: 3 × 3
Yearmeansd
<int><dbl><dbl>
201612.000.8164966
201713.757.5443135
201813.501.2909944
\n" ], "text/latex": [ "A tibble: 3 × 3\n", "\\begin{tabular}{lll}\n", " Year & mean & sd\\\\\n", " & & \\\\\n", "\\hline\n", "\t 2016 & 12.00 & 0.8164966\\\\\n", "\t 2017 & 13.75 & 7.5443135\\\\\n", "\t 2018 & 13.50 & 1.2909944\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A tibble: 3 × 3\n", "\n", "| Year <int> | mean <dbl> | sd <dbl> |\n", "|---|---|---|\n", "| 2016 | 12.00 | 0.8164966 |\n", "| 2017 | 13.75 | 7.5443135 |\n", "| 2018 | 13.50 | 1.2909944 |\n", "\n" ], "text/plain": [ " Year mean sd \n", "1 2016 12.00 0.8164966\n", "2 2017 13.75 7.5443135\n", "3 2018 13.50 1.2909944" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "library(dplyr)\n", "result <- flight_data %>% \n", " group_by(Year) %>% \n", " summarize(mean = mean(Flights), sd = sd(Flights))\n", "head(result)" ] }, { "cell_type": "code", "execution_count": 89, "id": "a3ac3f6e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "12" ], "text/latex": [ "12" ], "text/markdown": [ "12" ], "text/plain": [ "[1] 12" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 4
YearQuarterFlightsDelays
<int><int><int><int>
120161116
220162125
320163133
420164125
520171104
620172 93
\n" ], "text/latex": [ "A data.frame: 6 × 4\n", "\\begin{tabular}{r|llll}\n", " & Year & Quarter & Flights & Delays\\\\\n", " & & & & \\\\\n", "\\hline\n", "\t1 & 2016 & 1 & 11 & 6\\\\\n", "\t2 & 2016 & 2 & 12 & 5\\\\\n", "\t3 & 2016 & 3 & 13 & 3\\\\\n", "\t4 & 2016 & 4 & 12 & 5\\\\\n", "\t5 & 2017 & 1 & 10 & 4\\\\\n", "\t6 & 2017 & 2 & 9 & 3\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 4\n", "\n", "| | Year <int> | Quarter <int> | Flights <int> | Delays <int> |\n", "|---|---|---|---|---|\n", "| 1 | 2016 | 1 | 11 | 6 |\n", "| 2 | 2016 | 2 | 12 | 5 |\n", "| 3 | 2016 | 3 | 13 | 3 |\n", "| 4 | 2016 | 4 | 12 | 5 |\n", "| 5 | 2017 | 1 | 10 | 4 |\n", "| 6 | 2017 | 2 | 9 | 3 |\n", "\n" ], "text/plain": [ " Year Quarter Flights Delays\n", "1 2016 1 11 6 \n", "2 2016 2 12 5 \n", "3 2016 3 13 3 \n", "4 2016 4 12 5 \n", "5 2017 1 10 4 \n", "6 2017 2 9 3 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "nrow(flight_data)\n", "head(flight_data)" ] }, { "cell_type": "code", "execution_count": 90, "id": "f644b850", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "Attaching package: ‘reshape’\n", "\n", "\n", "The following object is masked from ‘package:dplyr’:\n", "\n", " rename\n", "\n", "\n" ] }, { "data": { "text/html": [ "24" ], "text/latex": [ "24" ], "text/markdown": [ "24" ], "text/plain": [ "[1] 24" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 6 × 4
YearQuartervariablevalue
<int><int><fct><int>
120161Flights11
220162Flights12
320163Flights13
1720171Delays 4
1820172Delays 3
1920173Delays 4
\n" ], "text/latex": [ "A data.frame: 6 × 4\n", "\\begin{tabular}{r|llll}\n", " & Year & Quarter & variable & value\\\\\n", " & & & & \\\\\n", "\\hline\n", "\t1 & 2016 & 1 & Flights & 11\\\\\n", "\t2 & 2016 & 2 & Flights & 12\\\\\n", "\t3 & 2016 & 3 & Flights & 13\\\\\n", "\t17 & 2017 & 1 & Delays & 4\\\\\n", "\t18 & 2017 & 2 & Delays & 3\\\\\n", "\t19 & 2017 & 3 & Delays & 4\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 6 × 4\n", "\n", "| | Year <int> | Quarter <int> | variable <fct> | value <int> |\n", "|---|---|---|---|---|\n", "| 1 | 2016 | 1 | Flights | 11 |\n", "| 2 | 2016 | 2 | Flights | 12 |\n", "| 3 | 2016 | 3 | Flights | 13 |\n", "| 17 | 2017 | 1 | Delays | 4 |\n", "| 18 | 2017 | 2 | Delays | 3 |\n", "| 19 | 2017 | 3 | Delays | 4 |\n", "\n" ], "text/plain": [ " Year Quarter variable value\n", "1 2016 1 Flights 11 \n", "2 2016 2 Flights 12 \n", "3 2016 3 Flights 13 \n", "17 2017 1 Delays 4 \n", "18 2017 2 Delays 3 \n", "19 2017 3 Delays 4 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#install.packages(reshape)\n", "library(reshape)\n", "result <- melt(flight_data[,c('Year', 'Quarter', 'Flights', 'Delays')], \n", " id.vars = c(1,2))\n", "nrow(result)\n", "head(result[c(1:3,17:19), ])" ] }, { "cell_type": "markdown", "id": "9bfa9ee8", "metadata": {}, "source": [ "#### merge\n", "\n", "The function $merge$ can be used to join data frames. It can be used to produce inner, left, right, and outer joins. " ] }, { "cell_type": "code", "execution_count": 91, "id": "156b7407", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 5 × 2
cityvalue
<chr><dbl>
1Rio de Janeiro10
2Sao Paulo 12
3Paris 20
4New York 25
5Tokyo 18
\n" ], "text/latex": [ "A data.frame: 5 × 2\n", "\\begin{tabular}{r|ll}\n", " & city & value\\\\\n", " & & \\\\\n", "\\hline\n", "\t1 & Rio de Janeiro & 10\\\\\n", "\t2 & Sao Paulo & 12\\\\\n", "\t3 & Paris & 20\\\\\n", "\t4 & New York & 25\\\\\n", "\t5 & Tokyo & 18\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 5 × 2\n", "\n", "| | city <chr> | value <dbl> |\n", "|---|---|---|\n", "| 1 | Rio de Janeiro | 10 |\n", "| 2 | Sao Paulo | 12 |\n", "| 3 | Paris | 20 |\n", "| 4 | New York | 25 |\n", "| 5 | Tokyo | 18 |\n", "\n" ], "text/plain": [ " city value\n", "1 Rio de Janeiro 10 \n", "2 Sao Paulo 12 \n", "3 Paris 20 \n", "4 New York 25 \n", "5 Tokyo 18 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stores <- data.frame(\n", " city = c(\"Rio de Janeiro\", \"Sao Paulo\", \"Paris\", \"New York\", \"Tokyo\"),\n", " value = c(10, 12, 20, 25, 18))\n", "head(stores)\n" ] }, { "cell_type": "code", "execution_count": 92, "id": "96d229c2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 5 × 2
citycountry
<chr><chr>
1Rio de JaneiroBrazil
2Sao Paulo Brazil
3Paris France
4New York US
5Tokyo Japan
\n" ], "text/latex": [ "A data.frame: 5 × 2\n", "\\begin{tabular}{r|ll}\n", " & city & country\\\\\n", " & & \\\\\n", "\\hline\n", "\t1 & Rio de Janeiro & Brazil\\\\\n", "\t2 & Sao Paulo & Brazil\\\\\n", "\t3 & Paris & France\\\\\n", "\t4 & New York & US \\\\\n", "\t5 & Tokyo & Japan \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 5 × 2\n", "\n", "| | city <chr> | country <chr> |\n", "|---|---|---|\n", "| 1 | Rio de Janeiro | Brazil |\n", "| 2 | Sao Paulo | Brazil |\n", "| 3 | Paris | France |\n", "| 4 | New York | US |\n", "| 5 | Tokyo | Japan |\n", "\n" ], "text/plain": [ " city country\n", "1 Rio de Janeiro Brazil \n", "2 Sao Paulo Brazil \n", "3 Paris France \n", "4 New York US \n", "5 Tokyo Japan " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "divisions <- data.frame(\n", " city = c(\"Rio de Janeiro\", \"Sao Paulo\", \"Paris\", \"New York\", \"Tokyo\"),\n", " country = c(\"Brazil\", \"Brazil\", \"France\", \"US\", \"Japan\"))\n", "head(divisions)" ] }, { "cell_type": "code", "execution_count": 93, "id": "f60cefb0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A data.frame: 5 × 3
cityvaluecountry
<chr><dbl><chr>
1New York 25US
2Paris 20France
3Rio de Janeiro10Brazil
4Sao Paulo 12Brazil
5Tokyo 18Japan
\n" ], "text/latex": [ "A data.frame: 5 × 3\n", "\\begin{tabular}{r|lll}\n", " & city & value & country\\\\\n", " & & & \\\\\n", "\\hline\n", "\t1 & New York & 25 & US \\\\\n", "\t2 & Paris & 20 & France\\\\\n", "\t3 & Rio de Janeiro & 10 & Brazil\\\\\n", "\t4 & Sao Paulo & 12 & Brazil\\\\\n", "\t5 & Tokyo & 18 & Japan \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A data.frame: 5 × 3\n", "\n", "| | city <chr> | value <dbl> | country <chr> |\n", "|---|---|---|---|\n", "| 1 | New York | 25 | US |\n", "| 2 | Paris | 20 | France |\n", "| 3 | Rio de Janeiro | 10 | Brazil |\n", "| 4 | Sao Paulo | 12 | Brazil |\n", "| 5 | Tokyo | 18 | Japan |\n", "\n" ], "text/plain": [ " city value country\n", "1 New York 25 US \n", "2 Paris 20 France \n", "3 Rio de Janeiro 10 Brazil \n", "4 Sao Paulo 12 Brazil \n", "5 Tokyo 18 Japan " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stdiv <- merge(stores, divisions, by.x=\"city\", by.y=\"city\")\n", "head(stdiv)" ] }, { "cell_type": "code", "execution_count": 94, "id": "4cb961bd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
A tibble: 4 × 3
countrycountamount
<chr><int><dbl>
Brazil222
France120
Japan 118
US 125
\n" ], "text/latex": [ "A tibble: 4 × 3\n", "\\begin{tabular}{lll}\n", " country & count & amount\\\\\n", " & & \\\\\n", "\\hline\n", "\t Brazil & 2 & 22\\\\\n", "\t France & 1 & 20\\\\\n", "\t Japan & 1 & 18\\\\\n", "\t US & 1 & 25\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "A tibble: 4 × 3\n", "\n", "| country <chr> | count <int> | amount <dbl> |\n", "|---|---|---|\n", "| Brazil | 2 | 22 |\n", "| France | 1 | 20 |\n", "| Japan | 1 | 18 |\n", "| US | 1 | 25 |\n", "\n" ], "text/plain": [ " country count amount\n", "1 Brazil 2 22 \n", "2 France 1 20 \n", "3 Japan 1 18 \n", "4 US 1 25 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "result <- stdiv %>% group_by(country) %>% \n", " summarize(count = n(), amount = sum(value))\n", "head(result)" ] }, { "cell_type": "markdown", "id": "d2e3a3a0", "metadata": {}, "source": [ "#### statistical tests: t-test\n", "There are many statistical tests in R.\n", "One of the most used is the t-test. It checks if the mean of observations is not different from a theoretical value." ] }, { "cell_type": "code", "execution_count": 95, "id": "580b4fab", "metadata": {}, "outputs": [], "source": [ "weight <- c(60, 72, 57, 90, 95, 72) \n", "height <- c(1.75, 1.80, 1.65, 1.90, 1.74, 1.91)\n", "bmi <- weight/height^2 " ] }, { "cell_type": "code", "execution_count": 96, "id": "0d0b8c52", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "\tOne Sample t-test\n", "\n", "data: bmi\n", "t = 0.34488, df = 5, p-value = 0.7442\n", "alternative hypothesis: true mean is not equal to 22.5\n", "95 percent confidence interval:\n", " 18.41734 27.84791\n", "sample estimates:\n", "mean of x \n", " 23.13262 \n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "t.test(bmi, mu=22.5)" ] }, { "cell_type": "code", "execution_count": null, "id": "115d05d0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "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.3.1" } }, "nbformat": 4, "nbformat_minor": 5 }