layout: true <div class="my-footer"><span>Part I: Intuition and Paradigms</span></div> <!-- this adds the link footer to all slides, depends on my-footer class in css--> --- name: xaringan-title class: inverse, center, middle # Introduction to R: Concepts and Terminology <img src="https://casbbi.gmu.edu/wp-content/uploads/logo.png" alt="gmu" width="180"/> ### Part I: Intuition and Paradigms .large[Shea Fyffe | George Mason University | 19 Nov 2021] --- class: middle, center .sun[Thank you for being here...] 🎉 --- class: middle, center, inverse ### .raininline[Background] .large[.fancy[Why are we here?]] --- ### .raininline[Background: People I've Met] .fatinline[Since I've started the program I've provided `R` help to:] + ~100 people (rough estimate) + students (undergrad & grad), student organizations, *faculty*, alumni + psychology, business, education, engineering + even people from GMU unaffiliated with psychology (that I had never met in my life) reach out to me --- ## .raininline[Background: The Unconfident] .salt[I am *not* some magic wizard or gifted being.] .salt[In fact, I locked my keys in my car just a few weeks ago. A horse kicked me in the face as a child.] -- .sun[I struggle when people say they *can't* learn R. It's too difficult.] ### .suninline[I do not believe you.] --- ## .raininline[Background: The Confident] .sun[Those that I've met (not everyone but most) that say they *know* R.] + *Can't* tell me the difference in a `list` and a `data.frame` + They *can't* tell me the difference between `indexing` and `filtering` + It's all fun and games until they get an .heatinline[error]. --- ## These problems have no relation to those I've interacted with. -- ## .heatinline[They are completely related to how `R` is being taught and communicated.] --- # .heat[Disclaimer] ## I will come off as earnest, fanatical, and/or bombastic --- class: middle, center # .raininline[Introduction] --- class: middle <img src="src/figs/frodo.jpg" width="50%" style="float:right; margin-left:10px;" /> .large[.fancy[I'm here as your guide, but this will be *your* journey...]] -- .large[.fancy[Fast or slow it will be a journey nonetheless.]] --- class: middle # Intoduction: My Journey with GMU <img src="src/figs/paid-lab.jpg" width="50%" style="float:right; margin-left:10px;" /> + 4<sup>th</sup> year PhD *candidate*<sup>1</sup> + Working in the .raininline[Psychometrics and Individual Differences] (PAID) Lab + You can learn more about the PAID Lab [(link)](https://sites.google.com/view/paid-lab/home) + **Research Interests:** "alternative" ways to measure personality + Text + Games .footnote[[1] #blessed 😅] --- class: middle # Introduction: My Journey with R + Like many of you, I took interest in `R` during graduate school (the first time) + Started learning by translating `SPSS` syntax at former job + I've been using since 2016 -- + I consider R a hobby (yes, I *actually* enjoy it) + Developed several packages, which are mostly proprietary (e.g., `ips.tools`, `rta`, `GMU.vpa`) + Recently became a mentor in the R for Data Science (R4DS) Slack Channel ([join here](http://r4ds.io/join)) + I teach an undergrad course *Introduction to R Programming in the Social Sciences* (PSYC 461) --- class: middle, center # .raininline[Agenda: Friday (Part I)] --- ## 1. Mindset ### 🙈🙉🙊 Truth or Dare ###
What can R do? ###
Activity: Pictionary ###
What is R? ###
10 min break --- ## 2. Intuition ###
Computers: Dumb ###
Activity: What does this mean? ###
Paradigms: Symbols, Objects, and Values ###
10 min break --- ## 3. Navigation ###
Setup ###
RStudio and R Files ###
Assignment and Environments ###
Activity: Did you buy new furniture? ###
Byeee .footnote[.saltinline[Blue icon: interacting with R]] --- class: middle, center # .raininline[Agenda: Saturday (Part II)] --- ## 0. Friday Recap ###
What is R? ###
Setup, RStudio, and R Files ###
Paradigms: Objects, Assignment, and Environments --- ## 1. Speaking the Language ###
Activity: Speed Dating ###
Objects: The Words of R ###
Data Types & Data Structures ###
Vectors and Vectorization ###
15 min break --- ## 2. Nouns ###
Data frames ###
Importing and Exporting Data ###
Activity: Row, Row, Row Your Boat ###
15 min break .footnote[.saltinline[Blue icon: interacting with R]] --- ## 3. Verbs ###
Functions ###
Arguments and Calling ###
Activity: Hello World ###
Byeee .footnote[.saltinline[Blue icon: interacting with R]] --- class: middle, center # .raininline[Truth or Dare] --- class: middle, center, inverse ### .fatinline[Truth:] You do not need to become a "programmer" -- ### .raininline[Dare:] I dare to believe you could be --- class: middle, center, inverse ### .fatinline[Truth:] You do not need to learn R -- ### .raininline[Dare:] I dare you to try --- class: middle, center, inverse ### .fatinline[Truth:] `SPSS` is much easier to use -- ### .raininline[Dare:] I dare you to unistall it --- class: middle, center, inverse ### .fatinline[Truth:] You do not have time to learn R -- ### .raininline[Dare:] I dare you make time --- class: middle, center, inverse ### .fatinline[Truth:] `R` is a statistical programming language -- ### .raininline[Dare:] I dare you to use it for something else --- class: middle, center, inverse ### .fatinline[Truth:] We all love comfort -- ### .raininline[Dare:] I dare you to be uncomfortable --- class: middle, center, inverse # .fatinline[Truth:] `R` will frustrate you, it make you feel dumb, it's a dance that we aren't naturally comfortable with. --- class: center ### .suninline[**Goal:**] Start dancing, even if you don't know the steps...and keep dancing. <img src="https://media.giphy.com/media/xWeHVBrOlgLDXJoc0m/giphy-downsized-large.gif" height="60%"/> --- class: middle, center, inverse ### .fatinline[We will not talk about statistics nor R applied in a specific setting] -- ### .raininline[We will talk about R] --- class: middle, center, inverse .large[.fancy[Why?]] --- name: justification0 class: middle, center # .raininline[Justification] --- name: justification1 class: middle, center ### This is an .heat[intervention] ### It's time to stop .fancy[wagging the dog], .fancy[putting the cart before the horse], etc. <img src="src/figs/wag-the-dog.gif"/> --- name: justification2 class: middle, inverse, center # 🌶️ .heat[Spicy take] --- name: justification3 class: middle, inverse ### .suninline[An understanding of R is **just as important<sup>2</sup>** as an understanding of statistics and other content areas of psychology.] .footnote[[2] *important* does **not** imply *relevant*] --- name: justification4 class: inverse, middle ## .fancy[Sociomateriality Theory] .large[.center[.fancy[Our work, research, and lives (more generally) are inextricably tied to technology (Orlikowski & Scott, 2006). Thus, a firm understanding of technology is extremely valuable.]]] --- name: justification5 class: inverse, middle .sun[R is **not** *just* a statistical tool; it is a way to communicate with your computer—it is a *software language*.] .rain[This allows you to do some remarkable things: build your resume/cv, find a sense of community, boost your self-esteem, and save time.] --- name: justification0 class: middle, center # .raininline[What Can R Do?] --- class: inverse ### .saltinline[Data Collection] .saltinline[I could write a little program to collect *your* information from GMU's website...] ```r # a custom function to collect student info from gmu get_gmu_students <- function(url, print_results = FALSE) { .page <- rvest::html_elements( xml2::read_html(url), "div.bioBrief" ) .parsed_page <- lapply( .page, \(x) { .x <- rvest::html_text(rvest::html_children(x), trim = TRUE) if (length(.x) == 1L) { .x <- c(.x, NA) } .x } ) .res <- data.frame( student_name = sapply(.parsed_page, `[`, 1), research_interest = sapply(.parsed_page, `[`, 2) ) if (print_results) { return(rmarkdown::paged_table(.res)) } .res } ``` --- ### .saltinline[Data Collection] .saltinline[Maybe I want the research interests of the HFAC PhD students.] <style type="text/css"> /* Table width = 100% max-width */ .remark-slide table{ width: 50%; } /* Change the background color to white for shaded rows (even rows) */ .remark-slide thead, .remark-slide tr:nth-child(2n) { background-color: white; } </style> ```r get_gmu_students("https://psychology.gmu.edu/student-bios/hf-phd-students", print_results = TRUE) ``` <div data-pagedtable="false"> <script data-pagedtable-source type="application/json"> {"columns":[{"label":["student_name"],"name":[1],"type":["chr"],"align":["left"]},{"label":["research_interest"],"name":[2],"type":["chr"],"align":["left"]}],"data":[{"1":"Allegra M Ayala","2":"Human Factors/Applied Cognition"},{"1":"Jose A Calvo","2":"Human Factors/Applied Cognition: Driver Safety, Naturalistic Driving, Autonomous Vehicles, Driver Behavior"},{"1":"KRISTIN Carpenter","2":"Human Factors/Applied Cognition: Cognitive Development, Developmental Neuroscience, Educational Interventions, Literacy, Dyslexia"},{"1":"Dean Cisler","2":"Human Factors/Applied Cognition"},{"1":"Ryon Ryon Cumings","2":"NA"},{"1":"Erika P De Los Santos","2":"Human Factors/Applied Cognition: Cognitive training, stress resilience, vigilance, attention, working memory, simulation training, serious games, virtual environments"},{"1":"Nicholas Gazzia","2":"Human Factors/Applied Cognition"},{"1":"Ami Getu","2":"Human Factors/Applied Cognition"},{"1":"Kyle Hunter Hickerson","2":"Human Factors/Applied Cognition: Autonomous Vehicles, Trust in Automation, Aggressive Driving, Virtual Reality"},{"1":"Kenneth Jackson","2":"Human Factors/Applied Cognition: Human Performance, Wearable Technology, Multi-Tasking, Augmented Reality, Virtual Reality, Trust in Automation"},{"1":"Noushin Jamaatlou","2":"Human Factors/Applied Cognition"},{"1":"Liam Kettle","2":"Human Factors/Applied Cognition"},{"1":"Min Ji Kim","2":"Human Factors/Applied Cognition"},{"1":"Spencer Kohn","2":"Human Factors/Applied Cognition: Trust in Automation, Trust Repair, & Human-Automation Teams"},{"1":"Tomas Lapnas","2":"Human Factors/Applied Cognition"},{"1":"Amie Mackay","2":"Human Factors/Applied Cognition"},{"1":"Kara Masick","2":"NA"},{"1":"Ryan McGarry","2":"Human Factors/Applied Cognition: Distribution of Visual Attention, Cognitive Aging, and Cognitive Training using EEG and MRI"},{"1":"Justin Mensen","2":"Human Factors/Applied Cognition: Sustained Attention and Vigilance"},{"1":"Ali Momen","2":"Human Factors/Applied Cognition: Neuroscience, Social Psychology, and Robotics"},{"1":"Salim Adam Mouloua","2":"Neuroimaging using fNIRS and EEG/ERPs, Vigilance Decrement & Increment, Simulation Design, Extended Reality, and Neuromodulation"},{"1":"Rachel Nguyen","2":"Human Factors/Applied Cognition: Visual Attention and Search, Perception, Visuo-spatial Cognition, Augmented/ Virtual Reality"},{"1":"Raul Gabriel Ramirez","2":"Human Factors/Applied Cognition: Sustained Attention, Workload, Physiological Workload Measures"},{"1":"Andres Rosero","2":"Human Factors/Applied Cognition"},{"1":"Heath Heath Sharp","2":"Human Factors/Applied Cognition: Trust in Automation, Trust Resiliency, and Trust Repair"},{"1":"Stephanie Tulk","2":"Human Factors/Applied Cognition: Human-Computer Interaction, Human-Robot Interaction, Social and Cognitive Neuroscience, Cognitive Modeling, Artificial Intelligence and Citizen Science"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}} </script> </div> --- ### .saltinline[Data Collection] .saltinline[Or the research interests of the ADP PhD students.] ```r get_gmu_students("https://psychology.gmu.edu/student-bios/adp-phd-students", print_results = TRUE) ``` <div data-pagedtable="false"> <script data-pagedtable-source type="application/json"> {"columns":[{"label":["student_name"],"name":[1],"type":["chr"],"align":["left"]},{"label":["research_interest"],"name":[2],"type":["chr"],"align":["left"]}],"data":[{"1":"Alena N Alegrado","2":"Predictors and outcomes of in-school music enrollment"},{"1":"Rebecca Correll","2":"Applied Developmental Psychology: Parenting, autism, early intervention, acceptance and commitment therapy (ACT)"},{"1":"Marissa Davila","2":"NA"},{"1":"negar Fatahi","2":"NA"},{"1":"Lamin Fatty","2":"Applied Developmental Psychology: Child play, parent-child playful interactions, and parenting in relation to child social and emotional development"},{"1":"Vera Hawa","2":"Applied Developmental Psychology"},{"1":"Alison Hundertmark","2":"Applied Developmental Psychology: language development, early childhood learning environments, interventions serving disadvantaged communities"},{"1":"Haoyu Lin","2":"Applied Developmental Psychology: Early Childhood Social Emotional Developmental and Intervention"},{"1":"Victor M Ortiz Cortes","2":"Applied Developmental Psychology"},{"1":"Darian F Stapleton","2":"Applied Developmental Psychology: Pretend Play, Imagination, Video Games, Creativity, Psychology of the Arts"},{"1":"Nicole Stucke","2":"Applied Developmental Psychology: executive function; social cognition; intervention"},{"1":"Megan Stutesman","2":"Applied Developmental Psychology: Embodied cognition, social cognition, social and emotional development, psychology of the arts"},{"1":"Tevis L Tucker","2":"Applied Developmental Psychology: Student persistence within in-school music electives; role of school transition and musical instrument choice"},{"1":"Nicole White","2":"Applied Developmental Psychology"},{"1":"DaSean L. Young","2":"Applied Developmental Psychology: Discrimination, Social Dynamics, The Marching Arts, Intergroup Contact, Race and Sexuality"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}} </script> </div> --- ### .saltinline[Data Visualization] .saltinline[Or all the students on GMU's People Page.] ```r # here are the program abbreviations concentration <- c("adp", "cl", "cbn", "hf", "io") # we can combine them with degree urls <- c(paste0(concentration[-2],"-ma-students"), paste0(concentration,"-phd-students")) # get student data from each program all_students <- lapply( paste0("https://psychology.gmu.edu/student-bios/", urls), \(x) { .x <- get_gmu_students(x) .tmp <- strsplit(gsub(".*\\/([a-z]+)\\-(ma|phd)\\-students$", "\\1;\\2", x, perl = T ), ";") setNames( data.frame(do.call(rbind, .tmp), .x), c("concentration", "degree", names(.x)) ) } ) # combine data into one dataset all_students <- do.call(rbind, all_students) ``` ---
--- class: center ### .raininline[Embedding Music] .raininline[What if I wanted to show you my taste in music, so you could be disgusted?] ## 🤢 --- <iframe src="https://open.spotify.com/embed/playlist/4unxIYtG5uqtRWmw99QUpP?utm_source=generator" width="100%" height="380" frameBorder="0" allowfullscreen="" allow="autoplay data-external="1"; picture-in-picture"></iframe> --- # <i class="fas fa-clipboard-list" style="float:left"/></i> The List Goes On... -- ### <i class="fas fa-check-square" style="float:left"/></i> Automating document creation (e.g., surveys, emails, items) -- ### <i class="fas fa-check-square" style="float:left"/></i> Making websites and interactive web applications -- ### <i class="fas fa-check-square" style="float:left"/></i> Extracting information you want from PDFs and text documents -- ### <i class="fas fa-check-square" style="float:left"/></i> Managing data *efficiently* --- class: middle <img src="src/figs/fast.jpg" width="50%" style="float:right; margin-left:10px;" /> ## .heatinline[We can also do things...fast...real fast] --- class: center, middle #### Let's see how much time it would take to create a subscale—for example—for each of the .fancy[Big Five] personality factors. 10 items for each factor and 10,000 cases. -- ###
.fatinline[How long should this take?] --- Here is some code, just ignore it for now... ```r # custom function that can be found at # https://github.com/Shea-Fyffe/PsychStudent/blob/main/R/spss_functions.R create_subscale <- function(x, FUNCT, pattern = NULL, ...) { if (!inherits(x, "data.frame")) { stop("x must be a data.frame") } if (!is.null(pattern)) { if (length(pattern) > 1) { pattern <- paste0(pattern, collapse = "|") } x <- x[grep(pattern, names(x))] } x <- apply(x, 1, FUN = FUNCT, ...) return(x) } # load data (I've stored it on dropbox) drop_box_url <- "https://www.dropbox.com/s/r00l6ud1xm7i8b1/5_data.csv?raw=1" p16_data <- read.csv(drop_box_url) # print the dimensions cat(paste0(c("rows", "columns"), ":", dim(p16_data))) ``` ``` rows:10000 columns:57 ``` --- class: middle #### Now that we have the data, let's time ourselves. Starting now... ```r # get the time t0 <- Sys.time() ``` -- ```r # get the name of the dimensions personality_dims <- gsub("^([A-Z]).*", "\\1", names(p16_data)[-c(1:7)]) # remove the duplicates personality_dims <- unique(personality_dims) *sum_subscales <- lapply(personality_dims, function(.pers_dim) { * create_subscale(p16_data, FUNCT = sum, pattern = .pers_dim) *}) # combine them with the original data new_p16_data <- data.frame(p16_data, setNames(sum_subscales, paste0(personality_dims, "_sum_subscale"))) # get end time t1 <- Sys.time() ``` --- class: center ## .saltinline[Let's see...] -- #### .fatinline[0.12 seconds!] --- ``` Rows: 10,000 Columns: 26 $ E10 <int> 4, 1, 4, 2, 3, 4, 4, 4, 2, 2, 1, 1, 3, 2, 3, 2, 1, 3, 4~ $ N1 <int> 4, 4, 4, 4, 3, 4, 2, 4, 2, 3, 4, 2, 2, 3, 3, 3, 4, 2, 1~ $ N2 <int> 4, 2, 4, 5, 3, 4, 4, 3, 2, 2, 5, 4, 4, 4, 3, 5, 3, 4, 3~ $ N3 <int> 4, 4, 5, 5, 4, 5, 4, 4, 4, 3, 4, 2, 4, 5, 3, 4, 5, 2, 2~ $ N4 <int> 4, 5, 4, 5, 4, 4, 4, 4, 2, 3, 4, 1, 2, 4, 3, 4, 2, 4, 2~ $ N5 <int> 4, 5, 4, 5, 5, 4, 2, 4, 4, 4, 4, 5, 2, 4, 3, 4, 5, 1, 1~ $ N6 <int> 5, 5, 5, 5, 4, 5, 3, 5, 4, 4, 4, 2, 1, 5, 3, 4, 5, 4, 3~ $ N7 <int> 5, 5, 4, 5, 5, 4, 5, 5, 4, 4, 5, 4, 4, 4, 3, 4, 5, 5, 4~ $ N8 <int> 4, 2, 3, 1, 4, 4, 2, 3, 0, 4, 4, 3, 4, 4, 3, 4, 3, 4, 4~ $ N9 <int> 4, 4, 4, 3, 4, 4, 2, 4, 4, 4, 5, 4, 2, 2, 3, 4, 5, 4, 5~ $ N10 <int> 3, 1, 1, 3, 2, 2, 2, 2, 4, 1, 2, 3, 3, 1, 2, 4, 1, 1, 4~ $ O1 <int> 4, 3, 3, 2, 3, 2, 4, 4, 4, 4, 4, 4, 5, 4, 3, 5, 4, 3, 4~ $ O2 <int> 2, 2, 2, 2, 3, 1, 3, 3, 4, 2, 5, 2, 2, 4, 3, 2, 5, 4, 3~ $ O3 <int> 3, 4, 3, 2, 5, 4, 4, 4, 4, 4, 5, 4, 4, 4, 3, 4, 4, 4, 5~ $ O4 <int> 4, 2, 3, 2, 3, 4, 4, 4, 5, 4, 4, 4, 4, 5, 3, 5, 2, 4, 3~ $ O5 <int> 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 3, 5, 4, 4, 4~ $ O6 <int> 2, 2, 2, 4, 2, 4, 3, 4, 4, 1, 2, 4, 1, 4, 3, 4, 3, 3, 2~ $ O7 <int> 2, 2, 3, 5, 1, 2, 3, 2, 4, 3, 4, 4, 2, 5, 3, 4, 5, 1, 2~ $ O8 <int> 4, 3, 4, 4, 2, 5, 3, 4, 4, 1, 2, 4, 2, 4, 3, 4, 2, 1, 2~ $ O9 <int> 4, 4, 3, 5, 1, 3, 4, 4, 4, 2, 2, 4, 2, 4, 3, 4, 4, 1, 4~ $ O10 <int> 4, 4, 3, 4, 4, 4, 3, 3, 4, 2, 2, 2, 4, 4, 3, 4, 2, 1, 2~ $ A_sum_subscale <int> 29, 34, 34, 33, 31, 36, 31, 36, 35, 36, 43, 38, 38, 36,~ $ C_sum_subscale <int> 35, 30, 28, 29, 33, 27, 29, 29, 28, 28, 29, 23, 25, 33,~ $ E_sum_subscale <int> 29, 23, 25, 26, 26, 30, 21, 25, 28, 29, 31, 33, 28, 29,~ $ N_sum_subscale <int> 41, 37, 38, 41, 38, 40, 30, 38, 30, 32, 41, 30, 28, 36,~ $ O_sum_subscale <int> 32, 29, 29, 33, 28, 33, 35, 36, 41, 27, 34, 35, 30, 42,~ ``` --- class: middle, center # .raininline[**Activity:**] Pictionary .salt[ I will give you 1 of 5 prompts. Those on Zoom will be using emojis. Those in-person will be using paper and pencil. You'll have 2 minutes to communicate your prompt to your team. If you get it right you get a point. ] ### Setup time
10
:
00
--- class: middle, center # .raininline[**Activity:**] Pictionary: Prompt 1 .salt[ Those of you with prompt 1 start drawing emoji'ing.]
02
:
00
--- class: middle, center # .raininline[**Activity:**] Pictionary: Prompt 2 .salt[ Those of you with prompt 2 start drawing emoji'ing.]
02
:
00
--- class: middle, center # .raininline[**Activity:**] Pictionary: Prompt 3 .salt[ Those of you with prompt 3 start drawing emoji'ing.]
02
:
00
--- class: middle, center # .raininline[**Activity:**] Pictionary: Prompt 4 .salt[ Those of you with prompt 4 start drawing emoji'ing.]
02
:
00
--- class: middle, center # .raininline[**Activity:**] Pictionary: Prompt 5 .salt[ Those of you with prompt 5 start drawing emoji'ing.]
02
:
00
--- class: middle, center # .raininline[**Activity:**] Pictionary: Discussion ### How did everyone do? --- class: middle, center # .raininline[What is R?] --- class: middle # .raininline[What is R?] `SPSS`, `Excel`, `Google Docs` are software packages. Imagine communicating with people using only emojis. They are pre-packaged, easy to use, and can communicate things effectively (under certain circumstances)—this is like a *software package*. They have predefined functions, which allow you to pick an choose what you want to communicate to your computer. --- class: middle # .raininline[What is R?] `R` is a *programming language*, which are used to make software packages. For example, `SPSS` is written in the programming language `Java`. Imagine communicating with people by drawing. If you're bad at it, it becomes really obvious. It takes time to perfect. However, even with a basic understanding, you can communicate far more than emojis—you are able to draw your own pictures and write your own story. --- class: middle, center .rain[BREAK]
10
:
00
--- class: middle, center # .raininline[Intuition] --- ### R has no intuition What is the answer to the calculation below? ```r 3(10) ``` --- ```r 3(10) ``` ``` Error in eval(expr, envir, enclos): attempt to apply non-function ``` --- class: center # .raininline[**Activity:**] What is this? ###
--- class: center # .raininline[**Activity:**] What is this? ###
--- class: center ### It's merely a `symbol` that represents `data` or some `value` .large[
`<-` `"cocktail"` ] ### After `assigning` (`<-`) data to a symbol, we've created an `object` --- # .raininline[`R` starts with an understanding of a few things (e.g., numbers, letters, certain functions); however, most things need to be communicated to it.] ## It only knows the `objects` that are in it's `environment` --- ```r x ``` ``` Error in eval(expr, envir, enclos): object 'x' not found ``` #### Let's tell it what `x` is: ```r # x is 1 through 5 x <- 1:5 # now we ask R to interpret what we told it x ``` ``` [1] 1 2 3 4 5 ``` --- #### If we don't assign things `R` forgets... ```r "Hello, it's me" ``` ``` [1] "Hello, it's me" ``` ```r ls() ``` ``` [1] "all_students" "concentration" "create_subscale" "drop_box_url" [5] "get_gmu_students" "new_p16_data" "p16_data" "personality_dims" [9] "sum_subscales" "t0" "t1" "urls" [13] "x" ``` ```r y <- "Hello, it's me" ls() ``` ``` [1] "all_students" "concentration" "create_subscale" "drop_box_url" [5] "get_gmu_students" "new_p16_data" "p16_data" "personality_dims" [9] "sum_subscales" "t0" "t1" "urls" [13] "x" "y" ``` --- #### If we assign things to an object that `R` knows, it replaces that object Let's tell it what `x` is: ```r # what is y y ``` ``` [1] "Hello, it's me" ``` ```r # assign the new value 'goodbye' y <- "Goodbye" y ``` ``` [1] "Goodbye" ``` --- #### `R` want you to use symbols that are *syntactically* appropriate .heat[Don't lead with numbers] ```r 1z <- c("A", "B", "C") ``` ``` Error: <text>:1:2: unexpected symbol 1: 1z ^ ``` .heat[The letter `"A"` is different than the symbol `A`] ```r "A" <- c("A", "B", "C") ``` --- #### `R` is sensitive to case ```r # what was y again? y ``` ``` [1] "Goodbye" ``` ```r # let's try to replace it Y <- c("A", "B", "C") y == Y ``` ``` [1] FALSE FALSE FALSE ``` #### You can also use words (without quotes) ```r celebs <- c("Cher", "Jay-z", "Bono", "Adele") ``` ```r celebs[1:3] ``` ``` [1] "Cher" "Jay-z" "Bono" ``` --- class: middle, center # .raininline[So what?] --- .fat[this allows us to represent and manipulate lot's of data using just objects] ```r # let's split a large data.frame into multiple program_data <- split(all_students, all_students$concentration) ``` --- ```r # io head(program_data$io) ``` ``` concentration degree student_name 62 io ma Yasmeen Afsar 63 io ma Natalia Aguilar 64 io ma Sofie Alexandrides 65 io ma Nicole Aranda 66 io ma Georgia Bizzell 67 io ma Chelsea Blocker research_interest 62 Leadership, Selection, Diversity & Inclusion 63 Industrial/Organizational Psychology 64 Industrial/Organizational Psychology 65 <NA> 66 <NA> 67 Industrial/Organizational Psychology ``` ```r # clinical head(program_data$cl) ``` ``` concentration degree student_name 108 cl phd Thomas Deakin 109 cl phd Jason Feinberg 110 cl phd Beth M Foote 111 cl phd Sarah T. Giff 112 cl phd Stefanie F Gonçalves 113 cl phd Stephanie Hargrove research_interest 108 <NA> 109 Psychological well-being, emotion regulation, positive psychology 110 Clinical Psychology 111 Clinical Psychology: PTSD, trauma, couples, parenting, families, emotion socialization, military psychology, interpersonal impacts of psychopathology 112 Clinical Psychology: emotion, impulsivity, substance use, health risk behaviors, depression, adolescents, fMRI, heart rate variability 113 Clinical Psychology: Social justice in mental health services, violence against women and girls of color, Critical Race Theory, survivor-centered practice, program evaluation, and holistic health-based prevention and interventions. ``` --- class: middle, center # .raininline[Navigation] --- name: setup ## .raininline[Navigation]: Setup .suninline[Do you have R?] **Windows:**`C:\Program Files\R\...\Rgui.exe` **Mac:**`/Library/Frameworks/R.framework/Resources/library` .suninline[If you don't that's okay:] Install **R** from [CRAN for Windows](https://cran.r-project.org/bin/windows) **OR** [CRAN for Mac](https://cran.r-project.org/bin/macosx). If you have *Ubuntu*, you're free to go (you have bigger issues to solve). -- I recommended to using [RStudio](https://www.rstudio.com/products/rstudio/download). This is merely a software that sits atop R, it provides more functionality, and is more customizable—it makes things a lot easier. --- class: inverse, center, middle # Let's Begin --  --- class: inverse, center, middle ## .raininline[Open RStudio] --- class: middle, center .rain[BREAK]
10
:
00
--- # .raininline[**Activity:**] Did you buy new furniture? #### one of the most common errors in R ```r a <- "blah" # print an object we don't have in our environment print(A) ``` ``` [1] "A" "B" "C" ``` --- # .raininline[**Activity:**] Did you buy new furniture? ### .saltinline[I'm going to give you some code, and I would like you to tell me what objects are in the environment] --- # .raininline[**Activity:**] Did you buy new furniture? ### .fatinline[Problem 1] ```r sfa <- "sofa from ikea" couch <- "leather" plant <- couch sfA <- sfa ``` --- ### .fatinline[Problem 1: Results] ```r ls() ``` ``` [1] "couch" "plant" "sfa" "sfA" ``` --- ### .fatinline[Problem 2] ```r plants <- c("plant", "palm", "ivy") recl1ner <- "layz-e-boy" stuff <- c(recl1ner, plants) rm(recl1ner) ``` --- ### .fatinline[Problem 2: Results] ```r ls() ``` ``` [1] "plants" "stuff" ``` --- ### .fatinline[Last one...Problem 3] ```r "sofa from ikea" ``` ``` [1] "sofa from ikea" ``` ```r coffee_table <- "wood" coffee_tablE <- "steel" ``` --- ### .fatinline[Problem 3: Results] ```r ls() ``` ``` [1] "coffee_table" "coffee_tablE" ``` --- class: center .sun[.fancy[Our journey ends here...]] <img src="https://media.giphy.com/media/A6PcmRqkyMOBy/giphy.gif" height="60%"/> --- name: byyeee class: inverse, center, middle ### <i class="fab fa-github-square" style="float:left"></i> https://github.com/Shea-Fyffe ### <i class="fab fa-linkedin" style="float:left"></i> https://linkedin.com/in/sheafyffe/ ### <i class="fas fa-envelope-open" style="float:left"></i> sfyffe@gmu.edu -- # Thank you! ## See you tommorrow! .large[👋] .rain[.fancy[Feel free to reach out if you have any questions]]