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(tidytext) | |
library(ggplot2) | |
library(dplyr) | |
diamonds %>% | |
filter(cut %in% c("Fair", "Good")) %>% | |
count(price = ifelse(price < 2500, "lo", "hi"), cut, clarity) %>% | |
mutate(clarity = reorder_within(clarity, n, cut)) %>% | |
ggplot(aes(clarity, n)) + | |
geom_col() + |
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
# also works with sublime (subl) | |
code $(git diff --name-only master) | |
# relative is also useful depending on your working directory | |
code $(git diff --relative --name-only master) |
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(ggplot2) | |
library(tidyr) | |
library(dplyr, warn.conflicts = FALSE) | |
diamonds_sum <- diamonds %>% | |
mutate(across(cut, as.character)) %>% | |
group_by(cut) %>% | |
summarise(across(price, sum), across(carat, n_distinct), n = n()) | |
diamonds_sum |
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(rlang) | |
"select"(iris, Species) | |
fn_var <- "select" | |
expr((!!sym(fn_var))(iris, Species) %>% head) %>% | |
rlang::eval_tidy() |
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(recipes) | |
library(embed) | |
library(dplyr) | |
library(mlbench) | |
set.seed(124) | |
data(PimaIndiansDiabetes) | |
d <- PimaIndiansDiabetes |
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(tidyr) | |
library(dplyr) | |
set.seed(324) | |
d <- tibble( | |
org = c(1, 1, 1, 2, 2, 3, 3, 3), | |
sport = c("fb", "sc", "bb", "fb", "bb", "fb", "sc", "bb"), | |
v1 = rnorm(8), | |
v2 = rnorm(8) * 2, | |
v3 = rnorm(8) * 10 |
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(tidyverse) | |
test <- crossing( | |
teamid = c(1, 2, 3), | |
action = c("a", "b", "c") | |
) | |
test <- test %>% | |
group_by(action) %>% | |
mutate( | |
day30 = c(10, 20, 30), |
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(caret) | |
library(dplyr) | |
threshold_method <- function(method) { | |
thresh_code <- getModelInfo(method, regex = FALSE)[[1]] | |
thresh_code$type <- c("Classification") |
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
# https://unix.stackexchange.com/a/402398/286677 | |
"\e[A": history-search-backward | |
"\e[B": history-search-forward |
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
# http://sappingattention.blogspot.com/2018/06/meaning-chains-with-word-embeddings.html | |
cpath = function(matrix, w1, w2, blacklist = c()) { | |
p1 = matrix[[w1]] | |
p2 = matrix[[w2]] | |
base_similarity = cosineSimilarity(p1, p2) | |
pairsims = matrix %*% t(rbind(p1, p2)) | |
# Words closer to *either* candidate than the other word. These might be used eventually; mostly to save on computation in later steps. | |
decentsims = pairsims[apply(pairsims, 1, max) >= base_similarity[1],] |