get up and running
play

GET UP AND RUNNING TODAYS GOAL: GET ORIENTED TO RSTUDIO, MAKE A - PowerPoint PPT Presentation

GET UP AND RUNNING TODAYS GOAL: GET ORIENTED TO RSTUDIO, MAKE A PROJECT FOLDER https://www.r-project.org https://rstudio.com RStudio will be the control center for your R Projects >_ Current Objects Document Files, Graphs,


  1. GET UP AND RUNNING

  2. TODAY’S GOAL: GET ORIENTED TO RSTUDIO, MAKE A PROJECT FOLDER

  3. https://www.r-project.org https://rstudio.com

  4. RStudio will be the control center for your R Projects >_

  5. Current Objects Document Files, Graphs, Console Help >_

  6. if (is.empty.model(mt)) { x <- NULL z <- list(coefficients = if (mlm) matrix(NA_real_, 0, RStudio ncol(y)) else numeric(), residuals = Drives R y, fitted.values = 0 * y, weights = w, rank = 0L, df.residual = if (!is.null(w)) sum(w != 0) else ny) Produces Plots > Generates Documents

  7. THE RIGHT FRAME OF MIND

  8. TYPE OUT YOUR CODE BY HAND

  9. RSTUDIO AGAIN

  10. install.packages ("usethis", repos = "http://cran.rstudio.com") Paper, Report, Analysis, Notes, etc, in RMarkdown

  11. install.packages ("usethis", repos = "http://cran.rstudio.com") Console: Type or send code here, see results

  12. install.packages ("usethis", repos = "http://cran.rstudio.com") Project files, Plots, Help

  13. install.packages ("usethis", repos = "http://cran.rstudio.com") Inspect objects you create

  14. TASK: CREATE A PROJECT FOR YOUR NOTES

  15. Use RMarkdown TO PRODUCE & REPRODUCE YOUR OWN WORK

  16. 1. Lorem Ipsum Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. This is what we want to end up with: nicely formatted text, plots, and tables in an HTML, PDF, or Word file Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui o ffi cia deserunt mollit anim id est laborum.

  17. # Lorem Ipsum This is what our file actually looks like: plain Lorem ipsum dolor sit amet, consectetur adipisicing elit, text, mixing words and sed do *eiusmod tempor* incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation chunks of code ullamco laboris nisi ut aliquip ex ea commodo consequat. library (ggplot2) tea <- rnorm (100) biscuits <- tea + rnorm (100, 0, 1.3) In a Literate Programming data <- data.frame (tea, biscuits) approach to documents, p <- ggplot (data, aes (x = tea, y = biscuits)) + geom_point () + chunks of code are geom_smooth (method = "lm") + processed and replaced labs (x = "Tea", y = "Biscuits") + theme_bw () with their output print (p) Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

  18. What you type What you end up with Markdown Output Header # Header Subhead !" Subhead Plain text Plain text italics *italics* Once the chunks of R Code have all bold **bold** been run, a Markdown Processor verbatim `verbatim` turns the bits of marked-up plain 1. List 1. List 2. List 2. List text into properly-formatted ° Bullet 1 - Bullet 1 output in HTML, PDF, DOCX or ° Bullet 2 - Bullet 2 other file types. 1 Footnote. Footnote.[^1] [^1]: The footnote. 1 The footnote. Markdown is a way to put formatting instructions in plain-text documents

  19. # Lorem Ipsum Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do *eiusmod tempor* incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. library (ggplot2) tea <- rnorm (100) biscuits <- tea + rnorm (100, 0, 1.3) In a Literate Programming data <- data.frame (tea, biscuits) approach to documents, p <- ggplot (data, aes (x = tea, y = biscuits)) + geom_point () + chunks of code are geom_smooth (method = "lm") + processed and replaced labs (x = "Tea", y = "Biscuits") + theme_bw () with their output print (p) Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

  20. 1. Lorem Ipsum Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. In a Literate Programming approach to documents, chunks of code are processed and replaced with their output Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui o ffi cia deserunt mollit anim id est laborum.

  21. An Rmd document lets you keep your code and notes together in plain text And produce good-looking output in a range of formats

  22. An Rmd document lets you # Report notes.Rmd We can see this *relationship* in a scatterplot. keep your code and notes ```{r my-code} together in plain text p !" ggplot(data, mapping) p + geom_point() ``` As you can see, this plot looks pretty nice. knit in R Report notes.html We can see this relationship in a scatterplot. And produce good-looking y output in a range of formats x As you can see, this plot looks pretty nice.

  23. An Rmd document lets you # Report notes.Rmd We can see this *relationship* in a scatterplot. keep your code and notes ```{r my-code} together in plain text p !" ggplot(data, mapping) p + geom_point() ``` As you can see, this plot looks pretty nice. knit in R Report notes.docx We can see this relationship in a scatterplot. And produce good-looking y output in a range of formats x As you can see, this plot looks pretty nice.

  24. Header section provides metadata and sets options Code chunk Text with Markdown formatting In RStudio, code chunks can be "played" one at a time Chunks are Code chunks can have their replaced by their output when the own names and options document is made

  25. 1. Lorem Ipsum Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. RStudio will do all the work for you when it comes to processing your document—i.e., getting it from plain-text Rmd to HTML, Word, or PDF. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui o ffi cia deserunt mollit anim id est laborum.

  26. In general, your code is what’s “real” in your project, not the objects you create.

  27. Consider not showing your output inline

  28. GETTING ORIENTED

  29. The Tidyverse library (tidyverse) Loading tidyverse : ggplot2 Draw graphs Loading tidyverse : tibble Nicer data tables Loading tidyverse : tidyr Tidy your data Get data into R Loading tidyverse : readr Cool functional programming stu ff Loading tidyverse : purrr Action verbs for manipulating data Loading tidyverse : dplyr Course-Specific Library library (socviz)

  30. CODE YOU CAN TYPE AND RUN ## Inside chunks of code, lines beginning with ## the hash character are comments my_numbers <- c (1, 1, 4, 1, 1, 4, 1) OUTPUT my_numbers ## [1] 1 1 4 1 1 4 1 What R Looks Like

  31. FOUR THINGS TO KNOW ABOUT R

  32. 1: Everything has a Name my_numbers data p Some names are forbidden FALSE TRUE Inf for if break function

  33. 2. Everything is an Object > letters ## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z" You create objects by assigning a thing to a name named "gets" this stu ff thing my_numbers <- c (1, 2, 3, 1, 3, 5, 25)

  34. You create objects by assigning a thing to a name my_numbers <- c (1, 2, 3, 1, 3, 5, 25) The assignment operator performs the action of creating objects. Use a keyboard shortcut to type it: option - Mac alt - Windows

  35. 3. You do things with named objects using functions and operators named thing "gets" this stu ff my_numbers <- c (1, 2, 3, 1, 3, 5, 25) c() is a function that takes comma-separated numbers or strings and joins them together into a vector

  36. Functions take arguments, perform actions, Functions have parentheses produce outputs at the end of their name. This is where the inputs, or arguments go. “Take this object …” mean () mean (x = my_numbers) Named argument. “Calculate the mean of what, please?” These names are internal to functions.

  37. Functions take arguments, perform actions, produce outputs mean (my_numbers) If you just write the name of the input, R assigns it to the function’s arguments in order. Look at the function’s help page to see the order it expects its arguments.

Recommend


More recommend