<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="generator" content="pandoc" /> <meta name="author" content="B. Philipp Kleer" /> <meta name="copyright" content="CC BY-SA 4.0, B. Philipp Kleer"/> <title>Quiz</title> <style type="text/css"> code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ </style> <style type="text/css"> pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ </style> <script src="quiz_files/header-attrs-2.11/header-attrs.js"></script> <script src="quiz_files/jquery-3.6.0/jquery-3.6.0.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="quiz_files/bootstrap-3.3.5/css/readable.min.css" rel="stylesheet" /> <script src="quiz_files/bootstrap-3.3.5/js/bootstrap.min.js"></script> <script src="quiz_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script> <script src="quiz_files/bootstrap-3.3.5/shim/respond.min.js"></script> <style>h1 {font-size: 34px;} h1.title {font-size: 38px;} h2 {font-size: 30px;} h3 {font-size: 24px;} h4 {font-size: 18px;} h5 {font-size: 16px;} h6 {font-size: 12px;} code {color: inherit; background-color: rgba(0, 0, 0, 0.04);} pre:not([class]) { background-color: white }</style> <link href="quiz_files/slidy-2/styles/slidy.css" rel="stylesheet" /> <script src="quiz_files/slidy-2/scripts/slidy.js"></script> <script src="quiz_files/slidy_shiny-1/slidy_shiny.js"></script> <link href="quiz_files/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" /> <script src="quiz_files/pagedtable-1.1/js/pagedtable.js"></script> <script src="quiz_files/clipboard-2.0.6/clipboard.min.js"></script> <link href="quiz_files/xaringanExtra-clipboard-0.2.6/xaringanExtra-clipboard.css" rel="stylesheet" /> <script src="quiz_files/xaringanExtra-clipboard-0.2.6/xaringanExtra-clipboard.js"></script> <script>window.xaringanExtraClipboard(null, {"button":"<i class=\"fa fa-clipboard\"><\/i>","success":"<i class=\"fa fa-check\" style=\"color: #90BE6D\"><\/i>","error":"<i class=\"fa fa-times-circle\" style=\"color: #F94144\"><\/i>"})</script> <link href="quiz_files/font-awesome-5.1.0/css/all.css" rel="stylesheet" /> <link href="quiz_files/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet" /> <link rel="stylesheet" type="text/css" media="screen, projection, print" href="styles/style-slides.css" /> </head> <body> <div class="slide titlepage"> <h1 class="title">Quiz</h1> <h1 class="subtitle">Daten bändigen & visualisieren</h1> <p class="author"> B. Philipp Kleer </p> <p class="date">11. Oktober 2021</p> </div> <div id="was-macht-der-folgende-code" class="slide section level2"> <h1>Was macht der folgende Code?</h1> <div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%>%</span> </span> <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice</span>(<span class="fu">seq</span>(<span class="dv">1</span>, </span> <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="dv">1000</span>, </span> <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="dv">100</span>)) <span class="sc">%>%</span> </span> <span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(os <span class="sc">==</span> <span class="st">"iOS"</span>) <span class="sc">%>%</span></span> <span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(device) <span class="sc">%>%</span> </span> <span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="fu">mean</span>(timeOfUse))</span></code></pre></div> <ul class="incremental"> <li>der Datensatz <code>df</code> wird geteilt, wie wählen mit <code>seq()</code> jeden 100. Fall</li> <li>wir nehmen daraus dann nur Fälle, deren Variable <code>os</code> gleich <code>"iOS"</code> ist</li> <li>dann sortieren wir nachd er Variable <code>device</code></li> <li>zuletzt lassen wir den Mittelwert der Variable <code>timeOfUse</code> gruppiert nach <code>device</code> ausgeben.</li> </ul> </div> <div id="und-was-macht-dieser-code" class="slide section level2"> <h1>Und was macht dieser Code?</h1> <div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%>%</span> </span> <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(gndr, income, residence, inhabitants) <span class="sc">%>%</span> </span> <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">bind_rows</span>(df2) <span class="sc">%>%</span> </span> <span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">sizeOfTown =</span> <span class="fu">case_when</span>(inhabitants <span class="sc"><</span> <span class="dv">10000</span> <span class="sc">~</span> <span class="st">"small town"</span>,</span> <span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> inhabitants <span class="sc">></span> <span class="dv">10000</span> <span class="sc">&</span> inhabitants <span class="sc"><</span> <span class="dv">50000</span> <span class="sc">~</span> <span class="st">"city"</span>,</span> <span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> inhabitants <span class="sc">></span> <span class="dv">50000</span> <span class="sc">~</span> <span class="st">"large city"</span>))</span></code></pre></div> <ul class="incremental"> <li>aus dem Datensatz <code>df</code> werden die Variablen <code>gndr</code>, <code>income</code>, <code>residence</code> und <code>inhabitants</code> gefiltert</li> <li>danach fügen wir die Fälle aus dem Datensatz <code>df2</code> hinzu.</li> <li>zuletzt schaffen wir eine neue Variable <code>sizeOfTown</code>, die der Höhe der Einwohner:innen eine Beschreibung zuordnet (ordinale Variable)</li> </ul> </div> <div id="und-was-macht-dieser-code-1" class="slide section level2"> <h1>Und was macht dieser Code?</h1> <div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>df <span class="sc">%>%</span> </span> <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">bind_rows</span>(df3) <span class="sc">%>%</span> </span> <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(income <span class="sc">></span><span class="er">></span> <span class="dv">1000</span> <span class="sc">&&</span> <span class="at">gndr =</span> <span class="st">"female"</span>) <span class="sc">%>%</span> </span> <span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">sizeOfTown =</span> <span class="fu">case_when</span>(inhabitants <span class="sc"><</span> <span class="dv">10000</span> <span class="sc">~</span> <span class="st">"small town"</span>,</span> <span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> inhabitants <span class="sc">></span> <span class="dv">10000</span> <span class="sc">&</span> inhabitants <span class="sc"><</span> <span class="dv">50000</span> <span class="sc">~</span> <span class="st">"city"</span>,</span> <span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> inhabitants <span class="sc">></span> <span class="dv">50000</span> <span class="sc">~</span> <span class="st">"large city"</span>))</span></code></pre></div> <ul class="incremental"> <li>fehlerhaft Code!</li> <li>in <code>filter()</code> genutzte Anweisungen sind falsch!</li> <li>korrekt ist: <code>filter(income > 1000 & gndr == "female")</code></li> </ul> </div> <div id="das-wars-ab-zu-ggplot" class="slide section level2"> <h1>Das war’s! Ab zu <code>ggplot</code>!</h1> </div> <!-- dynamically load mathjax for compatibility with self-contained --> <script> (function () { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; document.getElementsByTagName("head")[0].appendChild(script); })(); </script> </body> </html>