Skip to content

R Resources

Michael Samuel edited this page May 25, 2022 · 28 revisions

https://cran.r-project.org/web/packages/ggpattern/vignettes/developing-patterns.html

  • R Markdown: The Definitive Guide:

  • tidyselect (https://tidyselect.r-lib.org/reference/language.html):

    • starts_with() ends_with() contains() matches() num_range() Select variables that match a pattern
    • all_of() any_of() Select variables from character vectors
    • everything() last_col() Select all variables or the last variable
    • where() Select variables with a function
    • distinct()
  • dplyr notes

    • filter (rows/observations)
      • filter(between(varName,low,high))
      • filter(near(varName,mid, tol=0.5))
    • select (columns/variables, can be used to order columns)
      • starts_with(): starts with a prefix
      • ends_with(): ends with a prefix
      • contains(): contains a literal string
      • matches(): matches a regular expression
      • num_range(): a numerical range like x01, x02, x03.
      • one_of(): variables in character vector.
      • everything(): all variable
    • mutate (add or alter columns/variable)
    • arrange (to sort by row values of one or more columns) - desc()
    • group_by
      • summarize
        • n (count)
        • sum
        • mean
        • row_number (to get ranks within each group?)
    • ungroup (or data.frame() to remove groupings)
    • rename
    • count
    • slice
    • sample_n(), sample_frac()
    • row_number()
    • across [apply a function (or functions) across multiple specified columns]
    • pull
      • e.g: dataFrame %>% filter(variable1 == myValue) %>% pull(variable2)
    • full_join, inter_join, left_join, right_join, semi_join, anti_join

R and Shiny Resources

Study/Learn:

Cairo -- https://www.rdocumentation.org/packages/Cairo/versions/1.5-9/topics/Cairo cowplot https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html


someone check these out: evaluate, digest, formatR, highR, yami, ropp, htmltools, catools, bitops, jasonlite, base64enc, rproject



  • library(summarytools)
    • freq() : frequency tables
    • ctable() : cross-tabulations
    • descr() : descriptive statistics
    • dfSummary() : data frame summaries

  • tidyr
    • missing value function
      • drop_na()
      • fill()
      • replace_na()


https://holtzy.github.io/Pimp-my-rmd/

R Graphics Cookbook, 2nd edition Winston Chang

R for Data Science, Garrett Grolemund Hadley Wickham

ggplot2 online version of work-in-progress 3rd edition of “ggplot2: elegant graphics for data analysis"

  • https://ggplot2-book.org/

  • Zev Ross Blog

  • Adding text to plot, e.g.:

    • dat <- data.frame(x = rnorm(5000, mean = 1, sd = 100), y = rnorm(5000, mean = 1, sd = 100))
    • LabelData <- tibble(var1=c(-200,-600),var2=c(200,400), var3=c("HERE","THERE"))
    • ggplot(dat , aes(x, y)) + geom_point(color="grey") + geom_text(data=LabelData,aes(var1,var2,label=var3))

R

replace_missings <- function(x, replacement) { is_miss <- is.na(x) x[is_miss] <- replacement message(sum(is_miss), " missings replaced by the value ", replacement) x }

dF <- replace_missings(dF, replacement = 0)

  • rvest for "web scraping"

  • magick for image processing

  • writelxl

  • map function in purrr -- learn this!

  • lubridate - for working with dates

  • stringr package - working with strings

    • str_sub(vec,start,end)
    • str_split
    • str_detect - can use with regular expressions
    • str_extract

https://www.blueskystatistics.com/Default.asp