Skip to content

Instantly share code, notes, and snippets.

View AkselA's full-sized avatar
💭
bugging/debugging

Aksel AkselA

💭
bugging/debugging
  • Sandnes, Norway
View GitHub Profile
@AkselA
AkselA / twoletter-pr.r
Last active May 31, 2023 12:30
Calculating pronunciation success rate per vowel in consonant-vowel words (Norwegian)
d <- "Date Word Pr. Corr.
19.01.23 py pwæ 0
19.01.23 ka ka 1
19.01.23 li li 1
19.01.23 se sæ 0
19.01.23 ba bae 0
19.01.23 ju djul 0
19.01.23 ty tæ 0
19.01.23 pi pi 1
19.01.23 se si 0
selfdestructor <- function(x) {
if (is.numeric(x)) {
fn <- paste0("selfdestructor_", x, "k")
} else {
fn <- paste0("selfdestructor_", x)
}
f <- function() {
message("You specified: x = ", x)
rm(list=fn, envir=.GlobalEnv)
message("Poof!")
funfun <- function() {
x <- readline("What's your name?\n")
x0 <- sample(strsplit(tolower(x), NULL)[[1]])
# number of possible unique permutations, taking account of
# non-distinct objects
np <- factorial(length(x0))/prod(factorial(table(x0)))
count <- 0
rfunfun(x, np, count)
}
@AkselA
AkselA / commit.command
Last active November 15, 2019 15:51
Assistance for initializing an R project. Start by doing devtools::source_gist("1b141fb44b6a8b982b5d80cb0dd48290", filename="proj_init.r"), then supply the appropriate arguments to proj_init()
#!/bin/bash
Dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $Dir
echo "Enter commit message"
read Message
if [ -z "$Message" ]
then
sides <- 8
lim <- 6
n <- 20
lb <- 12
ub <- 16
pbinom(ub, n, (sides-lim)/sides) - pbinom(lb-1, n, (sides-lim)/sides)
# 0.000935362
javascript:Qr=prompt('S%C3%B8k%20i%20siden%20etter','');if(Qr)location.href='http://www.google.com/search?&q=site:'+encodeURIComponent(window.location.hostname)+'+'+escape(Qr)
@AkselA
AkselA / t.test.partial example 1.r
Last active February 3, 2023 07:56
T-test for partially paired data
set.seed(1)
n <- 40
p <- 0.3
r <- 0.5
m <- MASS::mvrnorm(n, c(0, 0), matrix(c(1, r, r, 1), 2))
m <- t(t(m) * c(1, 2))
m <- t(t(m) + c(51, 50))
m <- round(m, 1)
@AkselA
AkselA / tied comparisons 1 functions.r
Last active August 21, 2018 10:43
functions and associated methods for doing logical comparisons with ties
# tied greater than
`%tgt%` <- function(x, y) {
v <- x > y
v[x == y] <- 0.5
v
}
tgt <- function(x, y) {
v <- x > y
v[x == y] <- 0.5
sampletext <- "Technically, five-bit codes began in the 17th century, when Francis Bacon developed the cipher now called Bacon's cipher. The cipher was not designed for machine telecommunications (it was instead a method of encrypting a hidden message into another) and, although in theory it could be adapted to that purpose, it only covered 24 of the 26 letters of the English alphabet (two sets of letters, I/J and U/V, were expressed with the same code) and contained no punctuation, spaces, numbers or control characters, rendering it of little use."
sampletext
#[1] "Technically, five-bit codes began in the 17th century, when Francis Bacon developed the cipher now called Bacon's cipher. The cipher was not designed for machine telecommunications (it was instead a method of encrypting a hidden message into another) and, although in theory it could be adapted to that purpose, it only covered 24 of the 26 letters of the English alphabet (two sets of letters, I/J and U/V, were expressed with the same code) and con
library(caret)
set.seed(1)
val <- runif(200)
# val <- rnorm(200)
k <- 35
length(val)/k
# 5.714286