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, warn.conflicts = FALSE) | |
library(gapminder) | |
probs <- c(0.1, 0.5, 0.9) | |
gapminder %>% | |
group_by(continent) %>% | |
summarise( | |
probs = probs, | |
across(is.numeric & !year, ~ quantile(.x, probs)) | |
) |
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
#!/bin/bash | |
# | |
# Installs the latest RStudio daily desktop build for OSX/macOS and Ubuntu(amd64) | |
# | |
# https://support.rstudio.com/hc/en-us/articles/203842428-Getting-the-newest-RStudio-builds | |
set -e | |
install_macos_daily() { | |
REDIRECT_URL="https://www.rstudio.org/download/latest/daily/desktop/mac/RStudio-latest.dmg" | |
echo "Discovering daily build from: ${REDIRECT_URL}" | |
# Perform a HEAD request to find the redirect target. We use the name of the |
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
# What's the most natural way to express this code in base R? | |
library(dplyr, warn.conflicts = FALSE) | |
mtcars %>% | |
group_by(cyl) %>% | |
summarise(mean = mean(disp), n = n()) | |
#> # A tibble: 3 x 3 | |
#> cyl mean n | |
#> <dbl> <dbl> <int> | |
#> 1 4 105. 11 | |
#> 2 6 183. 7 |
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) | |
library(gh) | |
library(lubridate) | |
library(glue) | |
repo <- tibble(json = unclass(gh("/user/repos", .limit = Inf))) | |
repo <- repo %>% | |
hoist(json, | |
owner = c("owner", "login"), |
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
# ======================================= | |
# = Enhancements to data tidying = | |
# = Hadley Wickham = | |
# = https://rstd.io/tidyhancements-2019 = | |
# ======================================= | |
# What is tidy data? ---------------------------------------------------------- | |
# 1. Each column is a variable. | |
# 2. Each row is an observation. | |
# 3. Each cell is a value. |
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) | |
enum_value <- function(x, values) { | |
structure( | |
x, | |
values = values, | |
) | |
} | |
enum <- function(...) { |
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) | |
library(rvest) | |
url <- "https://en.wikipedia.org/wiki/The_Great_British_Bake_Off_(series_3)" | |
page <- read_html(url) | |
table <- page %>% | |
html_nodes("table.wikitable") %>% | |
.[[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
# Constructor and basic methods --------------------------------------------- | |
new_rational <- function(n, d) { | |
stopifnot(is.integer(n), is.integer(d)) | |
stopifnot(length(n) == length(d)) | |
structure(list(d = d, n = n), class = "rational") | |
} | |
length.rational <- function(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
ruler <- function(width = getOption("width")) { | |
x <- seq_len(width) | |
y <- dplyr::case_when( | |
x %% 10 == 0 ~ as.character((x %/% 10) %% 10), | |
x %% 5 == 0 ~ "+", | |
TRUE ~ "-" | |
) | |
cat(y, "\n", sep = "") | |
cat(x %% 10, "\n", sep = "") | |
} |
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(class) | |
library(mass) | |
library(mva) | |
tst <- read.table("e:/uni/stats766/puktest.txt", header = TRUE) | |
tst.v <- tst[,1:7] | |
tst.g <- tst[,8] | |
trn <- read.table("e:/uni/stats766/puktrain.txt", header = TRUE) | |
trn.v <- trn[,1:7] | |
trn.g <- trn[,8] |