Skip to content

Instantly share code, notes, and snippets.

View m-Py's full-sized avatar

Martin Papenberg m-Py

View GitHub Profile
# in this program I test the sampling distribution of Cohen's q
library("MASS")
# sample sizes to generate correlation coefficients
n1 <- 100
n2 <- 100
sml <- 20000 # number of simulations
qs <- vector(length=length(sml))
@m-Py
m-Py / rndSequence.js
Created June 2, 2016 10:02
Generate an array of any length n returning an array that contains a random sequence with integers 0 to n-1
rndSequence = function(length) {
options = length;
option_sequence = [];
for (var i = 0; i < options; i++) {
if (option_sequence.length === 0) {
var rnd = Math.floor(Math.random()*options);
option_sequence.push(rnd);
}
else if (option_sequence.length > 0) {
var rnd = Math.floor(Math.random()*options);
@m-Py
m-Py / wordCountRmdFile.R
Last active February 2, 2018 11:46
Count words in Rmd file using the package wordcountaddin
# This function reads a Rmd file and returns the word count
# It uses the wordcountaddin and koRpus packages
text_stats_file <- function(rmdFile) {
rmd <- file(rmdFile, "rt")
text <- readLines(rmd)
conText <- ""
for (i in text) {
conText <- paste(conText, i)
}
close(rmd)