This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Convert Excel Dates | |
# Differences between Windows and Mac Serial number date systems | |
# https://support.microsoft.com/en-us/office/date-systems-in-excel-e7fe7167-48a9-4b96-bb53-5612a800b487#ID0EAACAAA=Windows | |
# Excel supports two date systems, the 1900 date system and the 1904 date system. | |
# Each date system uses a unique starting date from which all other workbook dates are calculated. | |
# All versions of Excel for Windows calculate dates based on the 1900 date system. | |
# Excel 2008 for Mac and earlier Excel for Mac versions calculate dates based on the 1904 date system. | |
# Excel 2016 for Mac and Excel for Mac 2011 use the 1900 date system, which guarantees date compatibility with Excel for Windows. | |
# For example, July 5, 2011, can have two different serial numbers, as follows: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# key_variables_completion.Rmd at https://statacumen.com/2021/03/28/r-key-variables-completion/ | |
library(tidyverse) | |
# Combine rows with different data values | |
f_coalesce_by_column <- | |
function( | |
dat | |
) { | |
# for matching group_by() keys, keeps first non-NA value for each column |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r codebook} | |
# http://sandsynligvis.dk/articles/18/codebook.html | |
# https://github.com/ekstroem/dataMaid | |
#library(dataMaid) | |
#dataMaid::makeCodebook(dat_PreScr, replace = TRUE, openResult = FALSE, codebook = TRUE) | |
#dataMaid::makeCodebook(dat_Elig , replace = TRUE, openResult = FALSE, codebook = TRUE) | |
#dataMaid::makeCodebook(dat_pdp , replace = TRUE, openResult = FALSE, codebook = TRUE) | |
# Author's blog posts on using | |
# https://sandsynligvis.dk/2017/08/21/datamaid-your-personal-assistant-for-cleaning-up-the-data-cleaning-process/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# =Lookup() is for whole cells https://support.microsoft.com/en-us/office/lookup-function-446d94af-663b-451d-8251-369d5e3864cb | |
# below is to replace a text string inside a longer string | |
# Original code: https://www.howtoexcel.org/vba/how-to-find-and-replace-multiple-text-strings-within-a-text-string/ | |
# How to use: https://www.howtoexcel.org/vba/how-to-use-the-vba-code-you-find-online/ | |
# Step 1: Enable the Developer tab in the Ribbon. | |
# Go to the File tab. | |
# Click Options section. | |
# Click the Customize Ribbon section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# don't print readr::read_csv() column types | |
options(readr.num_columns = 0) | |
options(readr.show_col_types = FALSE) | |
# remove attributes after readr::read_csv() | |
# attr(df, "spec") <- NULL | |
# remove $ and , from dollar amounts; (5) is negative 5, so remove ")" and replace "(" with "-" | |
`Demand Sales` = gsub("[(]", "-", gsub("[\\$,)]", "", `Demand Sales` )) %>% as.numeric() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r, eval = TRUE} | |
# XXX-xxx | |
######################################## ######################################## | |
####### STOP EVAL ######## ####### STOP EVAL ######## | |
######################################## ######################################## | |
knitr::opts_chunk$set(eval = FALSE) # TRUE | |
######################################## ######################################## | |
####### STOP EVAL ######## ####### STOP EVAL ######## | |
######################################## ######################################## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r, results='asis'} | |
# list of column variables for table | |
list_var_col_names <- "Group" | |
list_var_col_labels <- "Group" | |
# list of row variables for table | |
list_var_row_names <- c(Var[["list"]][["var_resp"]] , Var[["list"]][["var_covar"]] ) | |
list_var_row_labels <- c(Var[["label"]][["var_resp"]], Var[["label"]][["var_covar"]]) | |
fn_root <- "./out/tab1_vars_dx_demo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Read current files | |
# Assumed file naming structure is Filename_YYYYMMDD.csv | |
# list of all files | |
fn_list_data_raw <- dir("data/") | |
# filenames to match | |
fn_dat_list_in <- | |
c( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from inline to yaml chunk options | |
knitr::convert_chunk_header() | |
# Verbatim engine for instruction | |
# https://bookdown.org/yihui/rmarkdown-cookbook/verbatim-code-chunks.html |
OlderNewer