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
Sub parse_data() | |
Dim lr As Long | |
Dim ws As Worksheet | |
Dim vcol, i As Integer | |
Dim icol As Long | |
Dim myarr As Variant | |
Dim title As String | |
Dim titlerow As Integer | |
'This macro splits data into multiple worksheets based on the variables on a column found in Excel. |
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
#' @title Convert a numeric value into a natural language approximation string | |
#' | |
#' @description | |
#' This function takes a numeric value and returns a string that approximates the value in natural language. | |
#' | |
#' @param x A numeric value. | |
#' | |
#' @examples | |
#' approx_num(0.5) | |
#' # [1] "increased by a half" |
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
# data cleaning and utility | |
import numpy as np | |
import pandas as pd | |
import vivainsights as vi | |
import os | |
# timing code | |
import time | |
import random | |
import sys |
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
import requests | |
import pandas as pd | |
package_name = "vivainsights" | |
api_endpoint = f"https://pypistats.org/api/packages/{package_name}/overall" | |
response = requests.get(api_endpoint) | |
if response.status_code == 200: | |
data = response.json() |
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(networkD3) | |
## Nodes data frame describing all the nodes in the network | |
## The first entry in nodes dataframe is node 0, the next entry is node 1 and so on. | |
## The nodes dataframe must be sorted according to this sequence. | |
## This is the only way to tie the nodes dataframe to the links dataframe. | |
TestNodes <- data.frame(name = c("Alpha", | |
"Beta", | |
"Cat", |
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
# See <https://rpubs.com/mbounthavong/sample_size_power_analysis_R> | |
library(pwr) | |
# Sample size estimations for two proportions | |
# `pwr::ES.h()` computes effect size for two proportions | |
# n provides required sample size | |
p0 <- pwr.2p.test(h = ES.h(p1 = 0.60, p2 = 0.50), sig.level = 0.05, power = .80) | |
plot(p0) |
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
# estimate sample size via power analysis | |
from statsmodels.stats.power import TTestIndPower | |
# parameters for power analysis | |
effect = 0.8 | |
alpha = 0.05 | |
power = 0.8 | |
# perform power analysis | |
analysis = TTestIndPower() |
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
#' Sorts letters in a character string by alphabetical order | |
#' | |
#' Vectorised | |
str_arrange <- function(x){ | |
x %>% | |
stringr::str_split("") %>% # Split string into letters | |
purrr::map(~sort(.) %>% paste(collapse = "")) %>% # Sort and re-combine | |
as_vector() # Convert list into vector | |
} |
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
#' @title | |
#' Rank a data frame by grouping variable using base R | |
#' | |
#' @description | |
#' This function ranks a specified column in a data frame by group using entirely base R functions. | |
#' The underlying function is `rank()`, where additional arguments can be passed with `...`. | |
#' The grouping variable is specified as a string using the argument `group_var`, and the variable to rank is | |
#' specified using the argument `rank_var`. The operation is analogous to using `group_by()` followed by | |
#' `mutate()` in {dplyr}. | |
#' See example below using the base dataset `iris`. |
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
# multiply values based on weights | |
wtest <- | |
data.frame( | |
x = c("cats", "dogs", "birds", "cats"), | |
y = c(1, 2, 3, 2) | |
) | |
wtest[rep(seq_len(nrow(wtest)), wtest$y),] |
NewerOlder