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
| # 🎵 Welcome to the 🔥 Danger Zone 🎶 | |
| `<-` <- function(lhs, rhs) { | |
| assign(deparse(substitute(lhs)), rhs, envir = parent.frame()) | |
| print(rhs) | |
| } |
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) | |
| d <- read_table("./inst/input10.txt", col_names = FALSE) |> | |
| separate_longer_position(X1, 1) |> | |
| mutate(dist = if_else(X1 == "S", 0, NA)) |> | |
| mutate(x = if_else(X1 == "S", "L", X1)) # eyeballing | |
| NCOL <- sqrt(nrow(d)) | |
| top <- c("7", "|", "F") |
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) | |
| n_hood <- c(141,140,139,1,-1,-139,-140,-141) | |
| get_nhood <- function(x, lags = n_hood, fill = "x"){ | |
| collapse::flag(x, lags, fill = fill) |> | |
| as_tibble() |> | |
| unite("concat", sep = "") |> | |
| pull(concat) | |
| } |
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
| loc <- function(x) { log(m^2 / sqrt(s^2 + m^2)) } | |
| shape <- function(x) { sqrt(log(1 + (s^2 / m^2))) } |
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
| # Simple charts | |
| library(magrittr) | |
| d <- rnorm(1000, 1, 1) | |
| density(d) %>% plot | |
| d2 <- rlnorm(1000, 1, 1) | |
| density(d2) %>% plot |
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
| Sub Test_NamedRanges() | |
| For Each nm In ThisWorkbook.Names | |
| If nm.RefersToRange.Parent.Name = Sheet10.Name Then MsgBox nm.Name | |
| Next nm | |
| End Sub |
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
| table() | |
| prop.table(mytable) # cell percentages | |
| sort(table(x), decreasing = TRUE) | |
| # Show missing data in table as default | |
| table = function (..., useNA = 'ifany') base::table(..., useNA = useNA) |
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
| ## SETUP AND FUNCTIONS ------------------------------------------------- | |
| load_packages <- function(x) { | |
| # Install CRAN packages (if not already installed) | |
| .inst <- x %in% installed.packages() | |
| if(length(x[!.inst]) > 0) install.packages(x[!.inst]) | |
| # Load packages into session | |
| sapply(x, require, character.only = TRUE) | |
| } |
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
| no_missing <- function(x) sum(is.na(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
| read.url <- function(url, ...){ | |
| temporaryFile <- tempfile() | |
| download.file(url, destfile = temporaryFile, method = "curl") | |
| url.data <- read.csv(temporaryFile, ...) | |
| return(url.data) | |
| } |
NewerOlder