class: title-slide, middle, inverse .leftcol30[ <center> <img src="https://github.com/emse-p4a-gwu/emse-p4a-gwu.github.io/raw/master/images/p4a_hex_sticker.png" width=250> </center> ] .rightcol70[ # Week 1: .fancy[Getting Started with R] ### EMSE 4574: Intro to Programming for Analytics ### John Paul Helveston ### September 01, 2020 ] --- class: inverse, middle # Week 1: .fancy[Getting Started with R] ## 1. Course Introduction ## 2. Break: Install Course Tools ## 3. Getting started with R & RStudio ## 4. Operators & data types ## 5. Preview of HW 1 --- class: inverse, middle # Week 1: .fancy[Getting Started with R] ## 1. .orange[Course Introduction] ## 2. Break: Install Course Tools ## 3. Getting started with R & RStudio ## 4. Operators & data types ## 5. Preview of HW 1 --- # Meet your instructor! .leftcol30[.circle[ <img src="https://p4a.seas.gwu.edu/2020-Fall/images/helveston.jpg" width="300"> ]] .rightcol70[ ### John Helveston, Ph.D. .font80[ Assistant Professor, Engineering Management & Systems Engineering - 2016-2018 Postdoc at [Institute for Sustainable Energy](https://www.bu.edu/ise/), Boston University - 2016 PhD in Engineering & Public Policy at Carnegie Mellon University - 2015 MS in Engineering & Public Policy at Carnegie Mellon University - 2010 BS in Engineering Science & Mechanics at Virginia Tech - Website: [www.jhelvy.com](http://www.jhelvy.com/) ]] --- # Meet your tutors! .leftcol30[.circle[ <img src="https://p4a.seas.gwu.edu/2020-Fall/images/pantha.jpg" width="300"> ]] .rightcol70[ ### **Saurav Pantha** (aka "The Firefighter") - Graduate Assistant (GA) - Masters student in EMSE ] --- # Meet your tutors! .leftcol30[.circle[ <img src="https://p4a.seas.gwu.edu/2020-Fall/images/kim.png" width="300"> ]] .rightcol70[ ### **Jennifer Kim** (aka "The Monitor") - Learning Assistant (LA) - EMSE Junior & P4A alumni ] --- # Course orientation -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 496 512"><path d="M336.5 160C322 70.7 287.8 8 248 8s-74 62.7-88.5 152h177zM152 256c0 22.2 1.2 43.5 3.3 64h185.3c2.1-20.5 3.3-41.8 3.3-64s-1.2-43.5-3.3-64H155.3c-2.1 20.5-3.3 41.8-3.3 64zm324.7-96c-28.6-67.9-86.5-120.4-158-141.6 24.4 33.8 41.2 84.7 50 141.6h108zM177.2 18.4C105.8 39.6 47.8 92.1 19.3 160h108c8.7-56.9 25.5-107.8 49.9-141.6zM487.4 192H372.7c2.1 21 3.3 42.5 3.3 64s-1.2 43-3.3 64h114.6c5.5-20.5 8.6-41.8 8.6-64s-3.1-43.5-8.5-64zM120 256c0-21.5 1.2-43 3.3-64H8.6C3.2 212.5 0 233.8 0 256s3.2 43.5 8.6 64h114.6c-2-21-3.2-42.5-3.2-64zm39.5 96c14.5 89.3 48.7 152 88.5 152s74-62.7 88.5-152h-177zm159.3 141.6c71.4-21.2 129.4-73.7 158-141.6h-108c-8.8 56.9-25.6 107.8-50 141.6zM19.3 352c28.6 67.9 86.5 120.4 158 141.6-24.4-33.8-41.2-84.7-50-141.6h-108z"/></svg> Everything you need will be on the course website: ### https://p4a.seas.gwu.edu/2020-Fall/ <br> -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 576 512"><path d="M519.442 288.651c-41.519 0-59.5 31.593-82.058 31.593C377.409 320.244 432 144 432 144s-196.288 80-196.288-3.297c0-35.827 36.288-46.25 36.288-85.985C272 19.216 243.885 0 210.539 0c-34.654 0-66.366 18.891-66.366 56.346 0 41.364 31.711 59.277 31.711 81.75C175.885 207.719 0 166.758 0 166.758v333.237s178.635 41.047 178.635-28.662c0-22.473-40-40.107-40-81.471 0-37.456 29.25-56.346 63.577-56.346 33.673 0 61.788 19.216 61.788 54.717 0 39.735-36.288 50.158-36.288 85.985 0 60.803 129.675 25.73 181.23 25.73 0 0-34.725-120.101 25.827-120.101 35.962 0 46.423 36.152 86.308 36.152C556.712 416 576 387.99 576 354.443c0-34.199-18.962-65.792-56.558-65.792z"/></svg> Course is broken into **two chunks**: ### 1. Programming ### 2. Analytics --- # Homeworks (48% of grade) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"/></svg> ~Every week (12 total) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm57.1 350.1L224.9 294c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h48c6.6 0 12 5.4 12 12v137.7l63.5 46.2c5.4 3.9 6.5 11.4 2.6 16.8l-28.2 38.8c-3.9 5.3-11.4 6.5-16.8 2.6z"/></svg> Soft due dates (11pm Monday before class) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 576 512"><path d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"/></svg> **Don't abuse this flexibility** -- ## Two hard deadlines on homework submissions: ### 1. Oct. 20 (HWs 1-6) ### 2. Dec. 08 (HWs 7-12) --- # Quizzes (15% of grade) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"/></svg> In class every other week-ish (7 total, drop lowest 2) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm57.1 350.1L224.9 294c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h48c6.6 0 12 5.4 12 12v137.7l63.5 46.2c5.4 3.9 6.5 11.4 2.6 16.8l-28.2 38.8c-3.9 5.3-11.4 6.5-16.8 2.6z"/></svg> 5 minutes (3-5 questions) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M139.61 35.5a12 12 0 0 0-17 0L58.93 98.81l-22.7-22.12a12 12 0 0 0-17 0L3.53 92.41a12 12 0 0 0 0 17l47.59 47.4a12.78 12.78 0 0 0 17.61 0l15.59-15.62L156.52 69a12.09 12.09 0 0 0 .09-17zm0 159.19a12 12 0 0 0-17 0l-63.68 63.72-22.7-22.1a12 12 0 0 0-17 0L3.53 252a12 12 0 0 0 0 17L51 316.5a12.77 12.77 0 0 0 17.6 0l15.7-15.69 72.2-72.22a12 12 0 0 0 .09-16.9zM64 368c-26.49 0-48.59 21.5-48.59 48S37.53 464 64 464a48 48 0 0 0 0-96zm432 16H208a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h288a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-320H208a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h288a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16zm0 160H208a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h288a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16z"/></svg> [Example quiz](https://p4aquizdemo.formr.org/) -- > **Why quiz at all?** There's a phenomenon called the "retrieval effect" - basically, you have to _practice_ remembering things, otherwise your brain won't remember them (details in the book ["Make It Stick: The Science of Successful Learning"](https://www.hup.harvard.edu/catalog.php?isbn=9780674729018)). --- # Exams (32% of grade) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"/></svg> Midterm (weeks 1 - 6) on Oct. 20 -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M0 464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V192H0v272zm320-196c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM192 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-40zM64 268c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zm0 128c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H76c-6.6 0-12-5.4-12-12v-40zM400 64h-48V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H160V16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v48H48C21.5 64 0 85.5 0 112v48h448v-48c0-26.5-21.5-48-48-48z"/></svg> Final (weeks 1 - 13) on Dec. 15 --- ## **Grading**: Standard Course Component | Weight | Notes ---------------------|--------|----------------------------------- Homeworks | 48% | 12 x 4% each Quizzes | 15% | 5 x 3% each Midterm Exam | 12% | Final Exam | 20% | Participation | 5% | --- ## **Grading**: Alternative Minimum Grade (AMG) - Students who struggle early on, but work hard to succeed in 2nd half. - Highest possible grade is "C" Course Component | Weight -------------------|---- Best 10 Homeworks | 40% Best 4 Quizzes | 10% Midterm Exam | 10% Final Exam | 40% --- # Course policies <br> -- - ### **BE NICE. BE HONEST. DON'T CHEAT.** -- - ### Write your own code (even in "collaborative" assignments) -- - ### Don't cheat --- # How to succeed in this class .leftcol[ ### Take care of your brain - Sleep! - Exercise! - Eat good food! <img src="images/sleep_clean.jpg" width="300"> ] -- .rightcol[ ### Start HW early! ### Take breaks often! ### Ask for help! ] --- # [Getting Help](https://p4a.seas.gwu.edu/2020-Fall/ref-getting-help.html) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M94.12 315.1c0 25.9-21.16 47.06-47.06 47.06S0 341 0 315.1c0-25.9 21.16-47.06 47.06-47.06h47.06v47.06zm23.72 0c0-25.9 21.16-47.06 47.06-47.06s47.06 21.16 47.06 47.06v117.84c0 25.9-21.16 47.06-47.06 47.06s-47.06-21.16-47.06-47.06V315.1zm47.06-188.98c-25.9 0-47.06-21.16-47.06-47.06S139 32 164.9 32s47.06 21.16 47.06 47.06v47.06H164.9zm0 23.72c25.9 0 47.06 21.16 47.06 47.06s-21.16 47.06-47.06 47.06H47.06C21.16 243.96 0 222.8 0 196.9s21.16-47.06 47.06-47.06H164.9zm188.98 47.06c0-25.9 21.16-47.06 47.06-47.06 25.9 0 47.06 21.16 47.06 47.06s-21.16 47.06-47.06 47.06h-47.06V196.9zm-23.72 0c0 25.9-21.16 47.06-47.06 47.06-25.9 0-47.06-21.16-47.06-47.06V79.06c0-25.9 21.16-47.06 47.06-47.06 25.9 0 47.06 21.16 47.06 47.06V196.9zM283.1 385.88c25.9 0 47.06 21.16 47.06 47.06 0 25.9-21.16 47.06-47.06 47.06-25.9 0-47.06-21.16-47.06-47.06v-47.06h47.06zm0-23.72c-25.9 0-47.06-21.16-47.06-47.06 0-25.9 21.16-47.06 47.06-47.06h117.84c25.9 0 47.06 21.16 47.06 47.06 0 25.9-21.16 47.06-47.06 47.06H283.1z"/></svg> Use [Slack](https://emse-p4a-f20.slack.com/) to ask questions. -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M208 352c-2.39 0-4.78.35-7.06 1.09C187.98 357.3 174.35 360 160 360c-14.35 0-27.98-2.7-40.95-6.91-2.28-.74-4.66-1.09-7.05-1.09C49.94 352-.33 402.48 0 464.62.14 490.88 21.73 512 48 512h224c26.27 0 47.86-21.12 48-47.38.33-62.14-49.94-112.62-112-112.62zm-48-32c53.02 0 96-42.98 96-96s-42.98-96-96-96-96 42.98-96 96 42.98 96 96 96zM592 0H208c-26.47 0-48 22.25-48 49.59V96c23.42 0 45.1 6.78 64 17.8V64h352v288h-64v-64H384v64h-76.24c19.1 16.69 33.12 38.73 39.69 64H592c26.47 0 48-22.25 48-49.59V49.59C640 22.25 618.47 0 592 0z"/></svg> Meet with your tutors -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M496 224c-79.6 0-144 64.4-144 144s64.4 144 144 144 144-64.4 144-144-64.4-144-144-144zm64 150.3c0 5.3-4.4 9.7-9.7 9.7h-60.6c-5.3 0-9.7-4.4-9.7-9.7v-76.6c0-5.3 4.4-9.7 9.7-9.7h12.6c5.3 0 9.7 4.4 9.7 9.7V352h38.3c5.3 0 9.7 4.4 9.7 9.7v12.6zM320 368c0-27.8 6.7-54.1 18.2-77.5-8-1.5-16.2-2.5-24.6-2.5h-16.7c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16h-16.7C60.2 288 0 348.2 0 422.4V464c0 26.5 21.5 48 48 48h347.1c-45.3-31.9-75.1-84.5-75.1-144zm-96-112c70.7 0 128-57.3 128-128S294.7 0 224 0 96 57.3 96 128s57.3 128 128 128z"/></svg> [Schedule a meeting](https://jhelvy.appointlet.com/b/professor-helveston) w/Prof. Helveston: - Tuesdays from 3:30-4:30pm - Wednesdays from 2:00-4:30pm - Fridays from 12:00-2:00pm -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M278.9 511.5l-61-17.7c-6.4-1.8-10-8.5-8.2-14.9L346.2 8.7c1.8-6.4 8.5-10 14.9-8.2l61 17.7c6.4 1.8 10 8.5 8.2 14.9L293.8 503.3c-1.9 6.4-8.5 10.1-14.9 8.2zm-114-112.2l43.5-46.4c4.6-4.9 4.3-12.7-.8-17.2L117 256l90.6-79.7c5.1-4.5 5.5-12.3.8-17.2l-43.5-46.4c-4.5-4.8-12.1-5.1-17-.5L3.8 247.2c-5.1 4.7-5.1 12.8 0 17.5l144.1 135.1c4.9 4.6 12.5 4.4 17-.5zm327.2.6l144.1-135.1c5.1-4.7 5.1-12.8 0-17.5L492.1 112.1c-4.8-4.5-12.4-4.3-17 .5L431.6 159c-4.6 4.9-4.3 12.7.8 17.2L523 256l-90.6 79.7c-5.1 4.5-5.5 12.3-.8 17.2l43.5 46.4c4.5 4.9 12.1 5.1 17 .6z"/></svg> [GW Coders](http://gwcoders.github.io/) --- # <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M501.1 395.7L384 278.6c-23.1-23.1-57.6-27.6-85.4-13.9L192 158.1V96L64 0 0 64l96 128h62.1l106.6 106.6c-13.6 27.8-9.2 62.3 13.9 85.4l117.1 117.1c14.6 14.6 38.2 14.6 52.7 0l52.7-52.7c14.5-14.6 14.5-38.2 0-52.7zM331.7 225c28.3 0 54.9 11 74.9 31l19.4 19.4c15.8-6.9 30.8-16.5 43.8-29.5 37.1-37.1 49.7-89.3 37.9-136.7-2.2-9-13.5-12.1-20.1-5.5l-74.4 74.4-67.9-11.3L334 98.9l74.4-74.4c6.6-6.6 3.4-17.9-5.7-20.2-47.4-11.7-99.6.9-136.6 37.9-28.5 28.5-41.9 66.1-41.2 103.6l82.1 82.1c8.1-1.9 16.5-2.9 24.7-2.9zm-103.9 82l-56.7-56.7L18.7 402.8c-25 25-25 65.5 0 90.5s65.5 25 90.5 0l123.6-123.6c-7.6-19.9-9.9-41.6-5-62.7zM64 472c-13.2 0-24-10.8-24-24 0-13.3 10.7-24 24-24s24 10.7 24 24c0 13.2-10.7 24-24 24z"/></svg> Course Tools (see [course prep lesson](https://p4a.seas.gwu.edu/2020-Fall/L0-course-prep.html)) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M94.12 315.1c0 25.9-21.16 47.06-47.06 47.06S0 341 0 315.1c0-25.9 21.16-47.06 47.06-47.06h47.06v47.06zm23.72 0c0-25.9 21.16-47.06 47.06-47.06s47.06 21.16 47.06 47.06v117.84c0 25.9-21.16 47.06-47.06 47.06s-47.06-21.16-47.06-47.06V315.1zm47.06-188.98c-25.9 0-47.06-21.16-47.06-47.06S139 32 164.9 32s47.06 21.16 47.06 47.06v47.06H164.9zm0 23.72c25.9 0 47.06 21.16 47.06 47.06s-21.16 47.06-47.06 47.06H47.06C21.16 243.96 0 222.8 0 196.9s21.16-47.06 47.06-47.06H164.9zm188.98 47.06c0-25.9 21.16-47.06 47.06-47.06 25.9 0 47.06 21.16 47.06 47.06s-21.16 47.06-47.06 47.06h-47.06V196.9zm-23.72 0c0 25.9-21.16 47.06-47.06 47.06-25.9 0-47.06-21.16-47.06-47.06V79.06c0-25.9 21.16-47.06 47.06-47.06 25.9 0 47.06 21.16 47.06 47.06V196.9zM283.1 385.88c25.9 0 47.06 21.16 47.06 47.06 0 25.9-21.16 47.06-47.06 47.06-25.9 0-47.06-21.16-47.06-47.06v-47.06h47.06zm0-23.72c-25.9 0-47.06-21.16-47.06-47.06 0-25.9 21.16-47.06 47.06-47.06h117.84c25.9 0 47.06 21.16 47.06 47.06 0 25.9-21.16 47.06-47.06 47.06H283.1z"/></svg> [Slack](https://emse-p4a-f20.slack.com/) - ### [Link to join](https://join.slack.com/t/emse-p4a-f20/shared_invite/zt-gvto0fas-TXP6IRWdbSA_m_4UglGsLA) (also posted on Blackboard announcement). - ### Install Slack on your phone and **turn notifications on**! --- # <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M501.1 395.7L384 278.6c-23.1-23.1-57.6-27.6-85.4-13.9L192 158.1V96L64 0 0 64l96 128h62.1l106.6 106.6c-13.6 27.8-9.2 62.3 13.9 85.4l117.1 117.1c14.6 14.6 38.2 14.6 52.7 0l52.7-52.7c14.5-14.6 14.5-38.2 0-52.7zM331.7 225c28.3 0 54.9 11 74.9 31l19.4 19.4c15.8-6.9 30.8-16.5 43.8-29.5 37.1-37.1 49.7-89.3 37.9-136.7-2.2-9-13.5-12.1-20.1-5.5l-74.4 74.4-67.9-11.3L334 98.9l74.4-74.4c6.6-6.6 3.4-17.9-5.7-20.2-47.4-11.7-99.6.9-136.6 37.9-28.5 28.5-41.9 66.1-41.2 103.6l82.1 82.1c8.1-1.9 16.5-2.9 24.7-2.9zm-103.9 82l-56.7-56.7L18.7 402.8c-25 25-25 65.5 0 90.5s65.5 25 90.5 0l123.6-123.6c-7.6-19.9-9.9-41.6-5-62.7zM64 472c-13.2 0-24-10.8-24-24 0-13.3 10.7-24 24-24s24 10.7 24 24c0 13.2-10.7 24-24 24z"/></svg> Course Tools (see [course prep lesson](https://p4a.seas.gwu.edu/2020-Fall/L0-course-prep.html)) ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg> [R](https://cloud.r-project.org/) & [RStudio](https://rstudio.com/products/rstudio/download/) (Install both) -- .leftcol40[ After installed: <br> **Open this**: .noborder[<img src="images/rstudio_ball.png" width="75">] **Not this**: .noborder[<img src="images/Rlogo.png" width="75">] ] -- .rightcol60[ <br> R: **Engine** | RStudio: **Dashboard** ---------------------|------------------------ .noborder[<img src="images/engine.jpg" width="300">] | .noborder[<img src="images/dashboard.jpg" width="350">] ] --- # <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M501.1 395.7L384 278.6c-23.1-23.1-57.6-27.6-85.4-13.9L192 158.1V96L64 0 0 64l96 128h62.1l106.6 106.6c-13.6 27.8-9.2 62.3 13.9 85.4l117.1 117.1c14.6 14.6 38.2 14.6 52.7 0l52.7-52.7c14.5-14.6 14.5-38.2 0-52.7zM331.7 225c28.3 0 54.9 11 74.9 31l19.4 19.4c15.8-6.9 30.8-16.5 43.8-29.5 37.1-37.1 49.7-89.3 37.9-136.7-2.2-9-13.5-12.1-20.1-5.5l-74.4 74.4-67.9-11.3L334 98.9l74.4-74.4c6.6-6.6 3.4-17.9-5.7-20.2-47.4-11.7-99.6.9-136.6 37.9-28.5 28.5-41.9 66.1-41.2 103.6l82.1 82.1c8.1-1.9 16.5-2.9 24.7-2.9zm-103.9 82l-56.7-56.7L18.7 402.8c-25 25-25 65.5 0 90.5s65.5 25 90.5 0l123.6-123.6c-7.6-19.9-9.9-41.6-5-62.7zM64 472c-13.2 0-24-10.8-24-24 0-13.3 10.7-24 24-24s24 10.7 24 24c0 13.2-10.7 24-24 24z"/></svg> Course Tools (see [course prep lesson](https://p4a.seas.gwu.edu/2020-Fall/L0-course-prep.html)) <br> -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M634.91 154.88C457.74-8.99 182.19-8.93 5.09 154.88c-6.66 6.16-6.79 16.59-.35 22.98l34.24 33.97c6.14 6.1 16.02 6.23 22.4.38 145.92-133.68 371.3-133.71 517.25 0 6.38 5.85 16.26 5.71 22.4-.38l34.24-33.97c6.43-6.39 6.3-16.82-.36-22.98zM320 352c-35.35 0-64 28.65-64 64s28.65 64 64 64 64-28.65 64-64-28.65-64-64-64zm202.67-83.59c-115.26-101.93-290.21-101.82-405.34 0-6.9 6.1-7.12 16.69-.57 23.15l34.44 33.99c6 5.92 15.66 6.32 22.05.8 83.95-72.57 209.74-72.41 293.49 0 6.39 5.52 16.05 5.13 22.05-.8l34.44-33.99c6.56-6.46 6.33-17.06-.56-23.15z"/></svg> [GWU VPN](https://seascf.seas.gwu.edu/vpn-access) (Install Cisco AnyConnect VPN Client) -- ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M634.91 154.88C457.74-8.99 182.19-8.93 5.09 154.88c-6.66 6.16-6.79 16.59-.35 22.98l34.24 33.97c6.14 6.1 16.02 6.23 22.4.38 145.92-133.68 371.3-133.71 517.25 0 6.38 5.85 16.26 5.71 22.4-.38l34.24-33.97c6.43-6.39 6.3-16.82-.36-22.98zM320 352c-35.35 0-64 28.65-64 64s28.65 64 64 64 64-28.65 64-64-28.65-64-64-64zm202.67-83.59c-115.26-101.93-290.21-101.82-405.34 0-6.9 6.1-7.12 16.69-.57 23.15l34.44 33.99c6 5.92 15.66 6.32 22.05.8 83.95-72.57 209.74-72.41 293.49 0 6.39 5.52 16.05 5.13 22.05-.8l34.44-33.99c6.56-6.46 6.33-17.06-.56-23.15z"/></svg> + <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg> = [RStudio](https://rstudio.seas.gwu.edu/) online! --- class: inverse, middle # Week 1: .fancy[Getting Started with R] ## 1. Course Introduction ## 2. .orange[Break: Install Course Tools] ## 3. Getting started with R & RStudio ## 4. Operators & data types ## 5. Preview of HW 1 --- # <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M501.1 395.7L384 278.6c-23.1-23.1-57.6-27.6-85.4-13.9L192 158.1V96L64 0 0 64l96 128h62.1l106.6 106.6c-13.6 27.8-9.2 62.3 13.9 85.4l117.1 117.1c14.6 14.6 38.2 14.6 52.7 0l52.7-52.7c14.5-14.6 14.5-38.2 0-52.7zM331.7 225c28.3 0 54.9 11 74.9 31l19.4 19.4c15.8-6.9 30.8-16.5 43.8-29.5 37.1-37.1 49.7-89.3 37.9-136.7-2.2-9-13.5-12.1-20.1-5.5l-74.4 74.4-67.9-11.3L334 98.9l74.4-74.4c6.6-6.6 3.4-17.9-5.7-20.2-47.4-11.7-99.6.9-136.6 37.9-28.5 28.5-41.9 66.1-41.2 103.6l82.1 82.1c8.1-1.9 16.5-2.9 24.7-2.9zm-103.9 82l-56.7-56.7L18.7 402.8c-25 25-25 65.5 0 90.5s65.5 25 90.5 0l123.6-123.6c-7.6-19.9-9.9-41.6-5-62.7zM64 472c-13.2 0-24-10.8-24-24 0-13.3 10.7-24 24-24s24 10.7 24 24c0 13.2-10.7 24-24 24z"/></svg> Install Course Tools (see [course prep lesson](https://p4a.seas.gwu.edu/2020-Fall/L0-course-prep.html)) ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 448 512"><path d="M94.12 315.1c0 25.9-21.16 47.06-47.06 47.06S0 341 0 315.1c0-25.9 21.16-47.06 47.06-47.06h47.06v47.06zm23.72 0c0-25.9 21.16-47.06 47.06-47.06s47.06 21.16 47.06 47.06v117.84c0 25.9-21.16 47.06-47.06 47.06s-47.06-21.16-47.06-47.06V315.1zm47.06-188.98c-25.9 0-47.06-21.16-47.06-47.06S139 32 164.9 32s47.06 21.16 47.06 47.06v47.06H164.9zm0 23.72c25.9 0 47.06 21.16 47.06 47.06s-21.16 47.06-47.06 47.06H47.06C21.16 243.96 0 222.8 0 196.9s21.16-47.06 47.06-47.06H164.9zm188.98 47.06c0-25.9 21.16-47.06 47.06-47.06 25.9 0 47.06 21.16 47.06 47.06s-21.16 47.06-47.06 47.06h-47.06V196.9zm-23.72 0c0 25.9-21.16 47.06-47.06 47.06-25.9 0-47.06-21.16-47.06-47.06V79.06c0-25.9 21.16-47.06 47.06-47.06 25.9 0 47.06 21.16 47.06 47.06V196.9zM283.1 385.88c25.9 0 47.06 21.16 47.06 47.06 0 25.9-21.16 47.06-47.06 47.06-25.9 0-47.06-21.16-47.06-47.06v-47.06h47.06zm0-23.72c-25.9 0-47.06-21.16-47.06-47.06 0-25.9 21.16-47.06 47.06-47.06h117.84c25.9 0 47.06 21.16 47.06 47.06 0 25.9-21.16 47.06-47.06 47.06H283.1z"/></svg> [Slack](https://emse-p4a-f20.slack.com/) - ### [Link to join](https://join.slack.com/t/emse-p4a-f20/shared_invite/zt-gvto0fas-TXP6IRWdbSA_m_4UglGsLA) (also posted on Blackboard announcement). - ### Install Slack on your phone and **turn notifications on**! ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg> [R](https://cloud.r-project.org/) & [RStudio](https://rstudio.com/products/rstudio/download/) (Install both) ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M634.91 154.88C457.74-8.99 182.19-8.93 5.09 154.88c-6.66 6.16-6.79 16.59-.35 22.98l34.24 33.97c6.14 6.1 16.02 6.23 22.4.38 145.92-133.68 371.3-133.71 517.25 0 6.38 5.85 16.26 5.71 22.4-.38l34.24-33.97c6.43-6.39 6.3-16.82-.36-22.98zM320 352c-35.35 0-64 28.65-64 64s28.65 64 64 64 64-28.65 64-64-28.65-64-64-64zm202.67-83.59c-115.26-101.93-290.21-101.82-405.34 0-6.9 6.1-7.12 16.69-.57 23.15l34.44 33.99c6 5.92 15.66 6.32 22.05.8 83.95-72.57 209.74-72.41 293.49 0 6.39 5.52 16.05 5.13 22.05-.8l34.44-33.99c6.56-6.46 6.33-17.06-.56-23.15z"/></svg> [GWU VPN](https://seascf.seas.gwu.edu/vpn-access) (Install Cisco AnyConnect VPN Client) ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 640 512"><path d="M634.91 154.88C457.74-8.99 182.19-8.93 5.09 154.88c-6.66 6.16-6.79 16.59-.35 22.98l34.24 33.97c6.14 6.1 16.02 6.23 22.4.38 145.92-133.68 371.3-133.71 517.25 0 6.38 5.85 16.26 5.71 22.4-.38l34.24-33.97c6.43-6.39 6.3-16.82-.36-22.98zM320 352c-35.35 0-64 28.65-64 64s28.65 64 64 64 64-28.65 64-64-28.65-64-64-64zm202.67-83.59c-115.26-101.93-290.21-101.82-405.34 0-6.9 6.1-7.12 16.69-.57 23.15l34.44 33.99c6 5.92 15.66 6.32 22.05.8 83.95-72.57 209.74-72.41 293.49 0 6.39 5.52 16.05 5.13 22.05-.8l34.44-33.99c6.56-6.46 6.33-17.06-.56-23.15z"/></svg> + <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 581 512"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg> = [RStudio](https://rstudio.seas.gwu.edu/) online! --- class: inverse, middle # Week 1: .fancy[Getting Started with R] ## 1. Course Introduction ## 2. Break: Install Course Tools ## 3. .orange[Getting started with R & RStudio] ## 4. Operators & data types ## 5. Preview of HW 1 --- # RStudio Orientation .leftcol70[ <center> <img src="images/rstudio_panes.png" width=650> </center> ] .rightcol30[ - Know the boxes - Customize the layout - Customize the look - [Extra themes](https://github.com/gadenbuie/rsthemes) ] --- # Your first conveRsation ### Write stuff in the console, then press "enter" -- ‍Example: **addition** ```r 3 + 4 ``` ``` ## [1] 7 ``` -- ‍Example: **error** ```r 3 + "4" ``` ``` ## Error in 3 + "4": non-numeric argument to binary operator ``` --- # Storing values ### Use the "`<-`" symbol to assign _values_ to _objects_ -- ‍Example: ```r x <- 40 x ``` ``` ## [1] 40 ``` -- ```r x + 2 ``` ``` ## [1] 42 ``` --- # Storing values ### If you overwrite an object, R "forgets" the old value -- ‍Example: ```r x <- 42 x ``` ``` ## [1] 42 ``` -- ```r x <- 50 x ``` ``` ## [1] 50 ``` --- # Storing values ### You can also use the "`=`" symbol to assign values ### (but you really should use "`<-`") -- ‍Example: ```r x = 42 x ``` ``` ## [1] 42 ``` ```r y <- 42 y ``` ``` ## [1] 42 ``` --- # Storing values ### You can store more than just numbers -- ‍Example: ```r x <- "If you want to view paradise" y <- "simply look around and view it" ``` -- ```r x ``` ``` ## [1] "If you want to view paradise" ``` ```r y ``` ``` ## [1] "simply look around and view it" ``` --- # Storing values -- .leftcol[ ### **Pro tip 1**: ### Shortcut for "`<-`" symbol .left[ |OS | Shortcut |:--|:-------- |mac | `option` + `-` |windows | `alt` + `-` ] (see [here](https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts) for more shortcuts) ] -- .rightcol[ ### **Pro tip 2**: ### Always surround "`<-`" with spaces Example: ```r x<-2 ``` Does this mean `x <- 2` or `x < -2`? ] --- .leftcol[ ## R ignores **extra space** ```r x <- 2 y <- 3 z <- 4 ``` Check: ```r x ``` ``` ## [1] 2 ``` ```r y ``` ``` ## [1] 3 ``` ```r z ``` ``` ## [1] 4 ``` ] -- .rightcol[ ## R cares about **case** ```r number <- 2 Number <- 3 numbeR <- 4 ``` Check: ```r number ``` ``` ## [1] 2 ``` ```r Number ``` ``` ## [1] 3 ``` ```r numbeR ``` ``` ## [1] 4 ``` ] --- # Use `#` for comments ### R ignores everything after the `#` symbol Example: ```r speed <- 42 # This is mph, not km/h! speed ``` ``` ## [1] 42 ``` --- # Use meaningful variable names -- ‍**Example**: You are recording the speed of a car in mph <br> <br> -- **Poor** variable name: ```r x <- 42 ``` -- **Good** variable name: ```r speed <- 42 ``` -- **Even better** variable name: ```r car_speed_mph <- 42 ``` --- # Use standard casing styles .leftcol60[ <img src="images/horst_casing.jpg" width=600> Art by [Allison Horst](https://github.com/allisonhorst/stats-illustrations) ] -- .rightcol40[ I recommend using one of these: - `snake_case_uses_underscores` - `camelCaseUsesCaps` Example: ```r days_in_week <- 7 monthsInYear <- 12 ``` ] --- ## The workspace .leftcol[ View all the current objects: ```r objects() ``` ``` ## [1] "car_speed_mph" "days_in_week" "monthsInYear" "number" ## [5] "numbeR" "Number" "speed" "x" ## [9] "y" "z" ``` ] -- .rightcol[ Remove an object by name: ```r rm(number) objects() ``` ``` ## [1] "car_speed_mph" "days_in_week" "monthsInYear" "numbeR" ## [5] "Number" "speed" "x" "y" ## [9] "z" ``` ] --- # View prior code in history pane <img src="images/rstudio_panes.png" width=500> -- # Use "up" arrow see previous code --- # Staying organized <br> -- ## 1) Save your code in .R files > ### ‍File > New File > R Script -- ## 2) Keep work in R Project files > ### File > New Project... --- class: inverse
10
:
00
.leftcol[.font80[ ## Your turn ### A. Practice getting organized 1. Open RStudio and create a new R project called `week1`. 2. Create a new R script and save it as `practice.R`. 3. Open the `practice.R` file and write your answers to the question below in it. ]] .rightcol[.font80[ ### B. Creating & working with objects 1). Create objects to store the values in this table: | City | Area (sq. mi.) | Population | |-------------------|----------------|------------| | San Francisco, CA | 46.87 | 884,363 | | Chicago, IL | 227.63 | 2,716,450 | | Washington, DC | 61.05 | 693,972 | 2) Use the objects you created to answer the following questions: - Which city has the highest density? - How many _more_ people would need to live in DC for it to have the same population density as San Francisco? ]] --- class: inverse, middle # Week 1: .fancy[Getting Started with R] ## 1. Course Introduction ## 2. Break: Install Course Tools ## 3. Getting started with R & RStudio ## 4. .orange[Operators & data types] ## 5. Preview of HW 1 --- # R as a calculator .leftcol[ ### Basic operators: - Addition: `+` - Subtraction: `-` - Multiplication: `*` - Division: `/` ] -- .rightcol[ ### Other important operators: - Power: `^` - Integer Division: `%/%` - Modulus: `%%` ] --- # Integer division: `%/%` Integer division drops the remainder <br><br> -- ‍Example: ```r 4 / 3 # Regular division ``` ``` ## [1] 1.333333 ``` ```r 4 %/% 3 # Integer division ``` ``` ## [1] 1 ``` --- # Integer division: `%/%` Integer division drops the remainder<br><br> -- ‍What will this return? ```r 4 %/% 4 ``` -- ``` ## [1] 1 ``` -- What will this return? ```r 4 %/% 5 ``` -- ``` ## [1] 0 ``` --- # Modulus operator: `%%` Modulus returns the remainder _after_ doing integer division<br><br> -- ‍Example: ```r 5 %% 3 ``` ``` ## [1] 2 ``` <br> -- ```r 3.1415 %% 3 ``` ``` ## [1] 0.1415 ``` --- # Modulus operator: `%%` Modulus returns the remainder _after_ doing integer division<br><br> -- ‍What will this return? ```r 4 %% 4 ``` -- ``` ## [1] 0 ``` -- What will this return? ```r 4 %% 5 ``` -- ``` ## [1] 4 ``` --- ## Odds and evens with `n %% 2` -- .leftcol[ If `n %% 2` is `0`, `n` is **EVEN** ```r 10 %% 2 ``` ``` ## [1] 0 ``` ```r 12 %% 2 ``` ``` ## [1] 0 ``` Also works with negative numbers! ```r -42 %% 2 ``` ``` ## [1] 0 ``` ] -- .rightcol[ If `n %% 2` is `1`, `n` is **ODD** ```r 1 %% 2 ``` ``` ## [1] 1 ``` ```r 13 %% 2 ``` ``` ## [1] 1 ``` Also works with negative numbers! ```r -47 %% 2 ``` ``` ## [1] 1 ``` ] --- ## Number "chopping" with 10s -- .pull-left[ The mod operator (`%%`) "chops" a number and returns everything to the _right_ ```r 123456 %% 1 ``` ``` ## [1] 0 ``` ```r 123456 %% 10 ``` ``` ## [1] 6 ``` ```r 123456 %% 100 ``` ``` ## [1] 56 ``` ] -- .pull-right[ Integer division (`%/%`) "chops" a number and returns everything to the _left_ ```r 123456 %/% 1 ``` ``` ## [1] 123456 ``` ```r 123456 %/% 10 ``` ``` ## [1] 12345 ``` ```r 123456 %/% 100 ``` ``` ## [1] 1234 ``` ] --- ## Number "chopping" with 10s - `%%` returns everything to the _right_ (`"chop" ->`) - `%/%` returns everything to the _left_ (`<- "chop"`) - The "chop" point is always just to the _right_ of the chopping digit: <div style="width:1000px"> <table class="table table-condensed"> <thead> <tr class="header"> <th>Example</th> <th>“Chop” point</th> <th>“Chop” point description</th> </tr> </thead> <tbody> <tr class="odd"> <td><code>1234 %% 1</code></td> <td><code>1234 |</code></td> <td>Right of the <code>1</code>’s digit</td> </tr> <tr class="even"> <td><code>1234 %% 10</code></td> <td><code>123 | 4</code></td> <td>Right of the <code>10</code>’s digit</td> </tr> <tr class="odd"> <td><code>1234 %% 100</code></td> <td><code>12 | 34</code></td> <td>Right of the <code>100</code>’s digit</td> </tr> <tr class="even"> <td><code>1234 %% 1000</code></td> <td><code>1 | 234</code></td> <td>Right of the <code>1,000</code>’s digit</td> </tr> <tr class="odd"> <td><code>1234 %% 10000</code></td> <td><code>| 1234</code></td> <td>Right of the <code>10,000</code>’s digit</td> </tr> </tbody> </table> </div> --- # Comparing things: **Relational operators** -- .leftcol[ ### Compare if condition is `TRUE` or `FALSE` using: - Less than: `<` - Less than or equal to : `<=` - Greater than or equal to: `>=` - Greater than: `>` - Equal: `==` - Not equal: `!=` ] -- .rightcol[.code60[ ```r 2 < 2 ``` ``` ## [1] FALSE ``` ```r 2 <= 2 ``` ``` ## [1] TRUE ``` ```r (2 + 2) == 4 ``` ``` ## [1] TRUE ``` ```r (2 + 2) != 4 ``` ``` ## [1] FALSE ``` ```r "penguin" == "penguin" ``` ``` ## [1] TRUE ``` ]] --- # Comparing things: **Logical operators** -- .leftcol[ ### Make multiple comparisons with: - And: `&` - Or: `|` - Not: `!` ] -- .rightcol[.code60[ With "and" (`&`), every part must be `TRUE`, otherwise the whole statement is `FALSE`: ```r (2 == 2) & (3 == 3) ``` ``` ## [1] TRUE ``` ```r (2 == 2) & (2 == 3) ``` ``` ## [1] FALSE ``` ]] --- # Comparing things: **Logical operators** .leftcol[ ### Make multiple comparisons with: - And: `&` - Or: `|` - Not: `!` ] .rightcol[.code60[ With "or" (`|`), if _any_ part is `TRUE`, the whole statement is `TRUE`: ```r (2 == 2) | (3 == 3) ``` ``` ## [1] TRUE ``` ```r (2 == 2) | (2 == 3) ``` ``` ## [1] TRUE ``` ]] --- # Comparing things: **Logical operators** .leftcol[ ### Make multiple comparisons with: - And: `&` - Or: `|` - Not: `!` ] .rightcol[.code60[ The "not" (`!`) symbol produces the _opposite_ statement: ```r ! (2 == 2) ``` ``` ## [1] FALSE ``` ```r ! ((2 == 2) | (2 == 3)) ``` ``` ## [1] FALSE ``` ]] --- # Comparing things: **Logical operators** .cols3[ ### And: `&` "Are any of the statements `FALSE`"? ```r (2 == 2) & (2 == 3) & (4 == 4) ``` ``` ## [1] FALSE ``` ] -- .cols3[ ### Or: `|` "Are any of the statements `TRUE`"? ```r (2 == 2) | (2 == 3) | (4 == 7) ``` ``` ## [1] TRUE ``` ] -- .cols3[ ### `& > |` The `&` operator takes precedence over `|` ```r (2 == 2) | (2 == 3) & (4 == 7) ``` ``` ## [1] TRUE ``` ] --- # Comparing things: **Logical operators** .leftcol[ ### **Pro tip**: Use parentheses ```r !3 == 5 # Confusing ``` ``` ## [1] TRUE ``` ```r !(3 == 5) # Less confusing ``` ``` ## [1] TRUE ``` ] --- ## Other important points .leftcol[ ### R follows BEDMAS: 1. **B**rackets 2. **E**xponents 3. **D**ivision 4. **M**ultiplication 5. **A**ddition 6. **S**ubtraction ] -- .rightcol[ ### **Pro tip**: Use parentheses ```r 1 + 2 * 4 # Confusing ``` ``` ## [1] 9 ``` ```r 1 + (2 * 4) # Less confusing ``` ``` ## [1] 9 ``` ] --- class: inverse
10
:
00
# Your turn .font80[ Consider the following objects: ```r w <- TRUE x <- FALSE y <- TRUE ``` Write code to answer the following questions: 1. Fill in _relational_ operators to make the following statement return `TRUE`: `! (w __ x) & ! (y __ x)` 2. Fill in _logical_ operators to make this statement return `FALSE`: `! (w __ x) | (y __ x)` ] --- # Data Types |Type | Description | Example |:---------|:----------------------------|:--------- |`double` | Numbers w/decimals (aka "float") | `3.14` |`integer` | Numbers w/out decimals | `42` |`character` | Text (aka "string") | `"this is some text"` |`logical` | Used for comparing objects | `TRUE`, `FALSE` -- Use `typeof()` to assess the type of any variable: ```r typeof("hello") ``` ``` ## [1] "character" ``` --- # Numeric types (there are 2) -- .leftcol[ ## Integers No decimals (e.g. `7`) ] -- .rightcol[ ## Doubles (aka "float") Decimals (e.g. `7.0`) ] --- ## In R, numbers are "doubles" by default -- ‍Example: ```r typeof(3) ``` ``` ## [1] "double" ``` Even though it _looks_ like an integer, R assumes that `3` is really `3.0` <br><br> -- Make it an integer by adding `L`: ```r typeof(3L) ``` ``` ## [1] "integer" ``` --- # Character types -- ### Use single or double quotes around anything: ```r typeof('hello') ``` ``` ## [1] "character" ``` ```r typeof("3") ``` ``` ## [1] "character" ``` -- Use single / double quotes if the string _contains_ a quote symbol: ```r typeof("don't") ``` ``` ## [1] "character" ``` --- # Logical types -- .leftcol[ Logical data only have two values:<br>`TRUE` or `FALSE` ```r typeof(TRUE) ``` ``` ## [1] "logical" ``` ```r typeof(FALSE) ``` ``` ## [1] "logical" ``` ] -- .rightcol[ Note that these have to be in all caps,<br>and **not** in quotes: ```r typeof('TRUE') ``` ``` ## [1] "character" ``` ```r typeof(True) ``` ``` ## Error in typeof(True): object 'True' not found ``` ] --- # Logical types Use to answer questions about logical statements. Example: Is `1` greater than `2`? ```r 1 > 2 ``` ``` ## [1] FALSE ``` -- ‍Example: Is `2` greater than `1`? ```r 1 < 2 ``` ``` ## [1] TRUE ``` --- # Special values <!-- Adjust grid size...use 100 if no header --> <style> .wrapper { width: 70vw; height: 60vh; } </style> .wrapper[ .top-left[ **Infinity**: `Inf`<br>_really big numbers_ ```r 1/0 ``` ``` ## [1] Inf ``` ] .top-right[ **Not a Number**: `NaN`<br>_"not a number"_ ```r 0/0 ``` ``` ## [1] NaN ``` ] .bottom-left[ **Not available**: `NA`<br>_value is "missing"_ ] .bottom-right[ **No value**: `NULL`<br>_no value whatsoever_ ]] --- class: inverse # Your turn
05
:
00
## Will these return `TRUE` or `FALSE`? ## (try to answer first, then run the code to check) - `! typeof('3') == typeof(3)` - `(typeof(7) != typeof("FALSE")) | FALSE` - `! (typeof(TRUE) == typeof(FALSE)) & FALSE` --- # Final points <br> -- ## 1) [HW 1](https://p4a.seas.gwu.edu/2020-Fall/hw1-getting-started.html) Preview ## <svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"/></svg> Read carefully! <br> -- ## 2) Please take this [survey](https://p4aintrosurvey.formr.org/)