-
Notifications
You must be signed in to change notification settings - Fork 11
R Resources
-
janitor
- tabyl() - https://cran.r-project.org/web/packages/janitor/vignettes/tabyls.html
- clean_names()
-
dplyr - distinct()
-
ggpattern
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?)
- summarize
- 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
- filter (rows/observations)
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
- using/reinstalling and old version of a package
- shinyURL <- "https://cran.r-project.org/src/contrib/Archive/shiny/shiny_1.3.0.tar.gz"
- install.packages(shinyURL, repos=NULL,type="source")
- library(summarytools)
- freq() : frequency tables
- ctable() : cross-tabulations
- descr() : descriptive statistics
- dfSummary() : data frame summaries
- tidyr
- missing value function
- drop_na()
- fill()
- replace_na()
- missing value function
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"
-
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
-
looking at a data object
- summary()
- headtail(df) head() tail()
- glimpse(df)
- like a transposed version of print: columns run down the page, and data runs across. This makes it possible to see every column in a data frame.
- class() - what kind of object is it
-
tmap
-
fs package
- easy path names with path()
- getting name part and extension part from file names
- junk <- dir_info(all=TRUE,recursive = TRUE)
- path_ext(junk$path) path_file(junk$path)
-
haven - to read and write SAS
-
function to replace all NA values in a dataframe with, say 0
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