A collection of miscellaneous useful functions used across projects.
vals
to summarize frequency of values in a vectorn_unique
to count number of unique values in a vector%notin%
to test whether an element is NOT in a setdescribe
to tidily summarize a vectordescribe_df
to tidily summarize a dataframedescribe_NA
to tidily summarize missing datacount_NA_patterns
to return a count of each missingness pattern in datacount_all
to call dplyr::count()
on all columns in the dataframecor0
to tidily summarize pairwise correlationstable0
to call table()
with NA
s includedcross_table
to call gmodels::CrossTable()
with all proportions suppressedpval_to_symbol
to convert numeric p values to corresponding significance symbolspval_to_jama
to convert numeric p values to JAMA formatreplace_NAs_with_medians
to replace NA
s with medians throughout dataframeround0
to round all numeric columns in a dataframefnr_names
to find and replace patterns in names of a dataframekey
to create a random alphanumeric keytstamp
to create a timestampto_missind
to recode target column in dataframe to indicator of missingnesspad_number
to pad a number with leading zeroes when appropriateset_up_new_repo
to create basic file structure to start new analysisclear_output_dir
to delete all files in output/
bp
to make a noisemk
to source the RUNME.R
or MAKEFILE.R
in directorynotify_cell
to send a text to a cell phonefnr_wd
to find-and-replace in all files in a directorysource_lines
to source specific lines in a filesource_all
to source all files in a directorylp
to print tibble with all rows shownsave_session_info
to save a .txt
file with session infowpsave
to save ggplot
as both .png
and .pdf
and load in viewerwrite_wp
to save dataframe as both .csv
and .xlsx
tc
to write to the clipboardtc_as_comment
to write a string to the clipboard formatted as an 80-wide R commentcharvec_tc
to quickly create pasteable lists for codecharvec_to_casewhen_tc
to quickly create case_when()
statements for codecharvecs_to_named_charvec_tc
to quickly create a named character vector mapping 1 list to anothertidy_MIcombine
to tidily pool analysis results when using mitools
tidy_confusionMatrix
to tidy a confusion matrix from caret
get_varImp
to get a tidy summary of variable importance from caret::train
get_train_perf
to get a tidy summary of training performance from caret::train
mice
:inspect_pred.matrix
to check the pattern of which variables predict which in mice
modelfit_mice_for_diag
to iteratively find # iterations in mice
model necessary to get all Rhat
< 1.05plot_mice_convergence
to produce convergence plots for mice
modelplot_mice_distrib
to produce raw vs. imputed distribution plots for mice
modelcompare_mice_distrib
to compare descriptives on raw vs. imputed distributions for mice
model.sav
files:inspect_sav
to get metadata (e.g., variable labels) from a .sav
fileadd_sav_labels
to add variable labels based on a .sav
file or labelled R dataAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.