options(dplyr.summarise.inform = FALSE)
#https://www.tidyverse.org/blog/2020/05/dplyr-1-0-0-last-minute-additions/
git branch -m master main | |
git fetch origin | |
git branch -u origin/main main | |
git remote set-head origin -a |
path <- "https://github.com/owner/repo/raw/main/somedata.rds" | |
rdsdl <- function(path){ | |
readRDS(url(path, "rb")) | |
} |
### old way | |
```r | |
df %>% | |
mutate(row = row_number()) %>% | |
gather('column', 'source', -row, -N) # key = column, value = source, retain row and N | |
# further transforms | |
``` |
# I want 18 separate folders for graphic outputs, and 17 separate folders for different outputs | |
# they will be saved in the "output" folder under my main project directory | |
library(fs) | |
library(here) | |
here <- here::here() | |
tablenos <- paste0("table",seq(1:17)) | |
fignos <- paste0("fig",seq(1:18)) |
client_id | referral_id | team_desc | referral_date | discharge_date | unique_id | |
---|---|---|---|---|---|---|
1 | 1 | Apple | 2018-11-07T00:00:00Z | 2019-10-29T00:00:00Z | 1_1 | |
2 | 1 | Banana | 2018-03-30T00:00:00Z | 2_1 | ||
2 | 2 | Apple | 2020-03-14T00:00:00Z | 2021-02-12T00:00:00Z | 2_2 | |
3 | 1 | Banana | 2017-01-18T00:00:00Z | 2017-07-30T00:00:00Z | 3_1 | |
4 | 1 | Apple | 2020-09-02T00:00:00Z | 2021-02-09T00:00:00Z | 4_1 | |
4 | 2 | Apple | 2017-06-20T00:00:00Z | 2017-11-27T00:00:00Z | 4_2 | |
4 | 3 | Clementine | 2017-08-14T00:00:00Z | 4_3 | ||
4 | 4 | Clementine | 2019-04-13T00:00:00Z | 4_4 | ||
5 | 1 | Banana | 2019-11-21T00:00:00Z | 2020-05-09T00:00:00Z | 5_1 |
teams <- c("Apple", "Banana", "Clementine") | |
dates <- seq(as.Date("2017-01-01"), as.Date("2021-01-01"), "days") | |
# 5 columns- client id, referral id, team_desc, referral_date, discharge_date | |
test_frame <- purrr::map_dfr(1 : 100, function(x){ | |
rnum <- sample(1 : 5, 1) | |
team_name <- sample(teams, rnum, replace = TRUE) |
# columns to update: | |
char_cols <- c("areaname", "parent_area") | |
# 1. convert to character, then | |
# 2. replace '&' with 'and' | |
DT[,(char_cols) := lapply(.SD, as.character), .SDcols = char_cols] | |
DT[,(char_cols) := lapply(.SD, gsub, pattern = ' & ', replacement = ' and '), .SDcols = char_cols] | |
library(tidyverse) | |
library(lubridate) | |
## each id is a person, and each row is one episode | |
## the two episode for id 1 overlap! | |
example_dates <- tibble( | |
id = c(1,1,2,2), | |
date_start = ymd(c("2020-01-01", "2020-01-03","2020-04-01", "2020-04-15")), | |
date_end = ymd(c("2020-01-05", "2020-01-10", "2020-04-04", "2020-04-16")) | |
) #%>% |
library(dplyr) | |
library(data.table) | |
library(ggplot2) | |
library(cusumcharter) | |
library(purrr) | |
library(tidyr) | |
library(ggExtra) | |
# make the link dynamic |