This file contains hidden or 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
| # Set seed | |
| set.seed(123) | |
| test_lm <- lm(mtcars$mpg ~ as.matrix(mtcars[c("wt", "drat")])) | |
| test_glm <- glm(mtcars$mpg ~ as.matrix(mtcars[c("wt", "drat")]), | |
| family = gaussian()) | |
| # Are they the same? (Hint: yes) | |
| identical(coef(test_lm), coef(test_glm)) |
This file contains hidden or 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
| lm.fit.sparse <- function(x, | |
| y, | |
| w = NULL, | |
| offset = NULL, | |
| method = c("qr", "cholesky"), | |
| tol = 1e-07, | |
| singular.ok = TRUE, | |
| order = NULL, | |
| transpose = FALSE) { | |
| cld <- getClass(class(x)) |
This file contains hidden or 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
| library(crrri) | |
| # Function that uses headless Chrome to extract webpage html | |
| headless_ch_get <- function(url, | |
| user.agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", | |
| headless = TRUE, | |
| wait.for.page = 0, | |
| pause.before.closing = NULL, | |
| ip = NULL, | |
| port = NULL, |
This file contains hidden or 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
| library(dplyr) | |
| library(dtplyr) | |
| library(ggplot2) | |
| library(gt) | |
| library(lubridate) | |
| library(readr) | |
| library(stringr) | |
| library(tibble) | |
| library(tidyr) | |
| library(viridis) |
This file contains hidden or 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
| library(SnowballC) | |
| library(tidyverse) | |
| library(tidytext) | |
| test <- tibble("id" = 1:5, | |
| "message" = c("I went to play tennis", | |
| "We made almond pound cake and played ball", | |
| "All the cakes in the bakery were good", | |
| "We had a hearty lunch", | |
| "He had open heart surgery")) |
This file contains hidden or 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
| if (!"Hmisc" %in% rownames(installed.packages())) install.packages("Hmisc") | |
| packages <- Hmisc::Cs( | |
| conflicted, | |
| getPass, | |
| assertthat, | |
| testthat, | |
| here, | |
| magrittr, | |
| data.table, |
This file contains hidden or 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
| function New-VirtualEnv { | |
| param | |
| ( | |
| $VirtualEnvDir, | |
| $EnvName, | |
| $Deactivate | |
| ) | |
| # Create virtual env | |
| cd $VirtualEnvDir |
This file contains hidden or 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
| def any_adds_up(num_list, k): | |
| if not isinstance(k, int) or isinstance(k, float): | |
| raise TypeError("'k' must be numeric") | |
| if not isinstance(num_list, list): | |
| raise TypeError("'num_list' must be a list") | |
| return any([-(x - k) in num_list for x in num_list]) |
This file contains hidden or 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
| def mult_reduce(ls): | |
| out = ls[0] | |
| for i in range(1, len(ls)): | |
| out = out * ls[i] | |
| return out | |
| def mult_all_but_i(num_list): | |
| if len(num_list) < 2: | |
| raise ValueError("Undefined operation") | |
| return [mult_reduce(num_list[:i] + num_list[i+1 :]) for i |
This file contains hidden or 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
| def first_missing_positive(A): | |
| if not A or max(A) <= 0: | |
| return 1 | |
| target_list = list(range(1, max(A) + 2)) | |
| return min([x for x in target_list if x not in A]) |
OlderNewer