R Ladies October 3 2017 Introduction Pierina Cheung
R Ladies! October 3, 2017
Introduction • Pierina Cheung • Postdoc at Western • Developmental psychologist
Learning objectives • What is R? • How to load data into R • Data format (if we have time)
Before we start… • Help each other out. • Ask any questions you want. • Everything will be online. • Motivation & time • No critical nor sensitive period!
Whenever you’re learning a new tool, for a long time you’re going to suck… But the good news is that is typical, that’s something that happens to everyone, and it’s only temporary. • Hadley Wickham, at Dplyr tutorial, Use. R! 2014
She’s a mathematician!
How did I learn it?
some jargon dataframe = dataset (short form: df or d on internet) arguments = things that go into brackets/for functions to work assignment <- giving names, placeholder object = e. g. , dataframe, analysis, graph factor and levels = categorical variable (gender with levels male and female) library, package = add-ons, like SPSS modules length = number of observations
Using your keyboard • Ctrl + Enter, Command + Enter to run a line /block of code (cursor can be anywhere; no need to highlight) – Only exception is when you use +, esp in ggplot, R runs each line separately. • Shift + Enter to continue code in new line, indented • Up arrow keys in console will bring back previous lines of code (down = move forward)
How to name variables? • Be Descriptive! • No space in between words, use _ . or camel. Case (though camel. Case not the best for variables that are needed for reshaping) • Don’t begin the name with an digit • Try to use lowercase (to prevent typos) • Consistent naming across experiments http: //www 2. stat. duke. edu/~rcs 46/lectures_2015/ 01 -markdown-git/slides/naming-slides/namingslides. pdf
Quick intro • R and R studio • When to use script window vs. console • Object-oriented thinking, and the assignment symbol <- • Variable types: https: //dereksonderegger. github. io/570 L/4 -datatypes. html • Anything you do in R doesn’t actually change the raw data file
Where should your eyes be looking at? Script, just like SPSS syntax
If you create a variable / object using <See it appear here. New object
If you create a variable / object using <- Error message, otherwise nothing important here.
If your code doesn’t have <- Look here look here!!
Let’s dive into R!
Complete Beginners? Try Udemy 1. Sign up for an account on udemy. com 2. Sign up for the "R basics: R programming language" course on udemy https: //www. udemy. com/r-basics/ 3. Watch videos 1, 2, 3, and 9. 1 - R basics (3 min) 2 - A walkthrough of downloading R & Rstudio (5 min) 3 - the Rstudio interface (19 min) 9 - Three common mistakes in R beginners (11 min)
Udemy… 4. Read about the data types on this website (Chapter 4 only): https: //dereksonderegger. github. io/570 L/4 -datatypes. html It should take 10 minutes or less to read this page, and by the end of this short chapter, you should be able to explain the different data types in R. 5. Finally, watch video 10 on udemy - Your first lines of code (15 min)
Then try Datacamp • Slight more programming focused https: //www. datacamp. com/courses/freeintroduction-to-r
Some online resources to get you started Fundamentals of R (by Liz Page-Gould & Alex Danvers) • https: //osf. io/a 2 x 7 j/ • Check their wiki page Jenny Bryan’s website • https: //github. com/jennybc • http: //stat 545. com Hadley Wickham’s R for Data Science book (free) • http: //r 4 ds. had. co. nz
ggplot – 3 basic elements
Thank you! Questions? Feel free to email!!!! Don’t be shy. cheung. pierina@gmail. com Twitter: @pierinaski
Data format Wide format Long format
- Slides: 26