class: center, middle, inverse, title-slide .title[ # Just starting with RStudio ] .subtitle[ ## The architecture and language of R ] .author[ ### Tanner Levenhagen ] .author[ ### Salem State University MSIO Program ] .date[ ### 2022-12-05 ] --- name: download-R # First download R and RStudio 1. Click the links below to download R **FIRST**. Only download the one that matches your system's operating system. - [For Macs or iOS](https://cran.r-project.org/bin/macosx/) - [For Windows](https://cran.r-project.org/bin/windows/base/) 1. Click the links below to download RStudio. This is the nice interface that runs off of R. - [Scroll down and should see a 'download' blue square](https://www.rstudio.com/products/rstudio/download/#download) 1. If that does not work or you need a bit more guidance, [watch this YouTube video](https://youtu.be/TFGYlKvQEQ4), I found it very good taking you step by step downloading R and RStudio. 1. Open RStudio and take a look at what it looks like! ### .center[The next slide will show you what you should see the first time openning RStudio (I labeled them for clarity).] --- class: background-image: url(data:image/png;base64,#images/001.png) background-size: contain .pull-left[ <br> .left[ <br> ## R Script ] <br> <br> <br> <br> <br> <br> <br> <br> <br> .right[ ## Console ] <!-- end right --> ] <!-- end pull-left --> .pull-right[ .right[ <br> <br> <br> <br> ## Global Environment <br> <br> ## Navigator/Viewer ] ] --- name: parts-of-RStudio # The last slide shows the four major areas .pull-left[ ## R Script This is where you can store your **code** and can put your **comments** in your code. ## Console This is where your **output** is shown and where you can put **one line of code** at a time. ] <!-- end pull-left --> .pull-right[ ## Global Environment This is where **data is stored** like data frames, objects, vectors, lists... more on these later. ## Navigator/Viewer This is where **plots** are shown as well as where you can navigate your **file system** from your computer. ] <!-- end pull-right --> <br> .center[ ### These can be moved around to fit how you want your RStudio to look. ] <!-- end center --> --- name: change-appearance .left-column[ <br> ### I personally like the look of dark mode on my systems so you can follow these steps to change the appearance ] <!-- end left-column --> .right-column[ .panelset[ .panel[.panel-name[Step 1] Go to the `Tools` and `Global Options...` <img src="data:image/png;base64,#images/002.png" width="100%" /> ] <!-- end panel --> .panel[.panel-name[Step 2] Select `Appearance` and mess around with whatever you want to mess around with <img src="data:image/png;base64,#images/003.png" width="100%" /> ] <!-- end panel --> .panel[.panel-name[Final Step] Select `Apply` and look at the beautiful RStudio you created <img src="data:image/png;base64,#images/004.png" width="100%" /> ] <!-- end panel --> ] <!-- end panelset --> ] <!-- end right-column --> --- name: change-panes .left-column[ <br> ### I would like to have my console and global environment to switch places. ] <!-- end left-column --> .right-column[ .panelset[ .panel[.panel-name[Step 1] Go to the `Tools` and `Global Options...` <img src="data:image/png;base64,#images/005.png" width="100%" /> ] <!-- end panel --> .panel[.panel-name[Step 2] Select `Pane Layout` and select the drop down menus to select any option. <img src="data:image/png;base64,#images/006.png" width="100%" /> ] <!-- end panel --> .panel[.panel-name[Final Step] Select `Apply` and now the panes should be where you want them to be. <img src="data:image/png;base64,#images/007.png" width="100%" /> ] <!-- end panel --> ] <!-- end panelset --> ] <!-- end right-column --> --- # Types of 'Objects' in RStudio .pull-left[ ### Data Frames Like any SPSS dataview or Excel spreadsheet where each column has equal rows ### Matrices Acts very similar to a **Data Frame** that is 2 dimensional (row & columns) ### Vectors Holds a list of 'elements' of the same 'type' ] <!-- end pull-left --> .pull-right[ ### Lists Holds a list of elements of potentially different 'types' ### Arrays Can hold more than 2 dimensional tables (different sets of rows & columns) ### Factors Is the variables that have categorical information in them (male/female, days of the week) ] <!-- end pull-right --> --- # What can these objects hold? #### They are called **atomic vectors**, like when we meantioned 'type' .pull-left[ #### Logical These include `TRUE` an `FALSE`. Sometimes these can be written as just `T` `F`. Notice that they must be capitalized, this will almost always be the case with very few exceptions in R. #### Integer These are all numbers (`1, 4, 3.1` etc.) that also includes negatives and decimals. These do not require `""` around the inputs. ] <!-- end pull-left --> .pull-right[ #### Character These are generally words (`"Bob","Jill","Andrew"`) that need `""` around **each** input. You can also make numbers into characters by surrounding each number with `""` (`"1","4","3.1"`). #### Helpful Hint: >You can check what type you are looking at by using the `typeof()` function and it will output the type in your console. ] <!-- end pull-right --> --- .pull-left[ # What will you be coding? Firstly, it is important to mention that the coding needed to complete statistics is very little and should be thought of a tool to complete your analysis rather than a scary programmer black box. Or in the words of a professor of mine: > R is a means to an end, I am not a programmer and do not want to be. You can if you enjoy it but it's not for me. ~Psychometrics Professor Extraordinaire ] <!-- end pull-left --> .pull-right[ ### Parts to code #### Functions This is what you want to do to the data whether that be running a correlation or finding the mean of a variable. #### Arguments Inside of functions, there are things that can augment or clarify what you want the function to do. #### Data This is the actual data you are applying the functions and arguments too. This could be input directly or refer to a data frame you have stored in your global environment. ] <!-- end pull-right --> --- name: parts-of-code class: # What does the code even look like? .pull-left[ We will use some data inside RStudio by default where the data frame is named `mtcars` ```r summary(object = mtcars) ``` This will give a table for every variable in the data frame containing the... - minimum - 1st quartile - median - mean - 3rd quartile - maximum something like this: ``` Min. 1st Qu. Median Mean 3rd Qu. Max. 10.40 15.43 19.20 20.09 22.80 33.90 ``` ] <!-- end pull-left --> .pull-right[ ### The function is : `summary()` ### The argument is : `object =` ### The data is : `mtcars` .bg-white[ #### Helpful Hint: > If you want to know what a function does, the package it came from, or the various arguments the function has you can use the `?` infront of any function. Example: ```r ?summary ``` ] <!-- end bg-white --> ] <!-- end pull-right --> --- name: pop-quiz-1 class: inverse # *POP QUIZ* ## How can you clarify what you want a function to do ==exactly==? -- ### .white[Did you say to add an argument to the function? Then correct! Good job!] ### If not, go the the previous slide and read what the parts of a code are. --- # Other code things to keep in mind .pull-left[ - Create an organized filing system with your exploratory code, visualizations, future presentations, and your final code to be reproducible .center[ <img src="data:image/png;base64,#images/008.png" width="30%" /> ] <!-- end center --> - This filing system can cover most of what you would need in your coding adventures. There are other folders that may be necessary, however, you should keep them all lowercase so you minimize the amount of keys to press. ] <!-- end pull-left --> .pull-right[ - Most `functions` are spelled using lowercase letters with very few exceptions - We can easily refer to different types of objects by making other objects ```r # We will go through this code later friends_names <- c("Friend1", "Friend2") ``` - Now anytime we refer to `friends_names` it will output Friend1, Friend2 ] <!-- end pull-right --> --- name: end class: inverse center middle # Now that you know *about* RStudio, next time we will look at some applications and how to actually code