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
library(tidyverse) | |
tibble(group = c("A", "A", "B", "C"), | |
major = c("bio", "chem", "bio", "art")) %>% | |
group_by(group) %>% | |
summarise(major = str_c(major, collapse = "/")) %>% | |
separate(major, into = c("major1", "major2"), sep = "/") |
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
library(tidyverse) | |
mtcars %>% | |
ggplot(aes(x = wt, y = mpg, color = factor(cyl))) + | |
geom_point() + | |
scale_color_manual(values = c("red", "blue", "#80DBCA")) | |
# open Digital Color Meter on Mac, find the color you want, and get the RGB values from that application | |
# then put those colors in here, and use the resulting hex code in scale_color_manual |
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
library(tidyverse) | |
# much better way to do this --------------- | |
d <- tribble( | |
~species, ~low_1, ~high_1, ~low_2, ~high_2, ~shift, | |
"PRLC", 180, 740, 180, 990, "expansion", | |
"AMRE", 640, 690, 250, 780, "expansion", | |
"PETH", 180, 990, 180, 840, "contraction", | |
"PRBU", 180, 1000, 180, 1000, "no_change", |
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
library(tidyverse) | |
library(tidybayes) | |
d <- tibble(sensor_a = rnorm(100, 5, 2), | |
sensor_b = rnorm(100, 1, 1), | |
sensor_c = rnorm(100, 0, 3), | |
time = 1:100) | |
# pivot longer so all our sensor names are in one column, and readings in another | |
d <- d %>% |
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
library(tidyverse) | |
library(brms) | |
library(tidybayes) | |
d <- tibble(a = rnorm(1000, sd = 1), | |
b = rnorm(1000, sd = 5), | |
c = rnorm(1000, sd = 2), | |
d = rnorm(1000, sd = 1), | |
e = rnorm(1000, sd = 3)) |
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
attach(list( | |
`+` = function(a, b){ | |
noquote(paste0(sum(a,b,rnorm(1,0,0.0001)), "ish")) | |
}, | |
`(` = function(a){ | |
a*rnorm(1,1,0.001) | |
}, | |
`<-` = function(a,b){ |
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
library(tidyverse) | |
#devtools::install_github("AckerDWM/gg3D") | |
library("gg3D") | |
flights <- nycflights13::flights | |
flights %>% | |
drop_na() %>% | |
filter(dest %in% c("LAX", "SFO", "SMF")) %>% | |
ggplot(aes(x = hour, y = dep_delay, z = arr_delay, color = month, shape = origin)) + | |
axes_3D(theta = 280, phi = 20) + |
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
#!/bin/bash | |
find . -size +100M | sed 's|^\./||g' | cat >> .gitignore; awk '!NF || !seen[$0]++' .gitignore | |
sort -u .gitignore > .gitignore_new && mv .gitignore_new .gitignore | |
# thanks to https://stackoverflow.com/questions/4035779/gitignore-by-file-size#comment67586426_5200267 |
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
# run this BEFORE you reinstall R/RStudio | |
old_packages <- list.files(.libPaths()) | |
saveRDS(old_packages, "test_old_packages.rds") | |
# now you close RStudio and reinstall the new R and RStudio | |
# now you run THIS after you've installed R and RStudio anew | |
old_pkg_import <- readRDS("test_old_packages.rds") | |
pkgs_to_install <- unique(old_pkg_import) |
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
result <- matrix(nrow = nrow(mtcars), ncol = ncol(mtcars)-1) | |
for (i in 1:32) { | |
result[i,] <- rollapply(as.character(mtcars[i,]), 2, identical, c("1", "0")) | |
} | |
result2 <- vector(length = nrow(mtcars)) | |
for (i in 1:32) { | |
result2[i] <- TRUE %in% result[i,] | |
} |
NewerOlder