Skip to content

Instantly share code, notes, and snippets.

@msummersgill
msummersgill / Von_Mises_Combination_Method_Of_Moments.R
Last active January 3, 2024 18:22
Von Mises Combination Method of Moments
library(circular)
## Helper function to generate a circular object in degrees, 0-360
circularDeg <- function(x) circular(x,template = "geographics",units = "degrees", modulo = "2pi")
theta <- circularDeg(seq(from = 0, to = 360,by = 1))
m1 <- circularDeg(180)
k1 <- 2.1
w1 <- 65
dvm1 <- dvonmises(theta, mu = m1, kappa = k1)
library(data.table)
library(fastmatch)
#' Add rows to a data table in a memory efficient, by-referencesque manner
#'
#' This mimics the by-reference functionality `DT[, new_col := value]`, but
#' for rows instead. The rows in question are assigned at the end of the data
#' table. If the data table is keyed it is automatically reordered after the
#' operation. If not this function will preserve order of existing rows, but
#' will not preserve sortedness.
import numpy as np ## numpy version
import pandas as pd ## pandas version
import pyspark ## pypark version
from pyspark.sql import SQLContext
from pyspark.sql.types import IntegerType
from pyspark.sql.types import LongType
## Define dataframe row count
L = 5*365*86400
## /home/matthew14786/DatabricksTesting/Python-3.7.5/python
## installed (no explicit import) pyarrow version 3.0.0
import numpy as np ## numpy version 1.20.1
import pandas as pd ## pandas version 1.2.3
import pyspark ## pypark version 7.3.9
from pyspark.sql import SQLContext
from pyspark.sql.types import IntegerType
from pyspark.sql.types import LongType
@msummersgill
msummersgill / SparkRError.R
Last active April 7, 2021 21:59
SparkR Error Collecting Large SparkDataFrame
library(arrow)
## Open source Apache Spark downloaded from this archive:
## https://archive.apache.org/dist/spark/spark-3.0.1/spark-3.0.1-bin-hadoop2.7.tgz
library(SparkR, lib.loc = "~/DatabricksTesting/spark-3.0.1-bin-hadoop2.7/R/lib/")
## $java -version
## openjdk version "1.8.0_212"
## OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.16.04.1-b03)
## OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
library(data.table)
dta <- data.table(gr = LETTERS[1:3],
a = 1,
b = 1)
add <- function(x, y, group) if(group == "B") x + y else x - y
dta[,.BY, by = .(gr)]
library(shiny)
library(BatchGetSymbols)
ui <- fluidPage(
textInput('stock','stock',"GE"),
sliderInput('length', 'length', min = 1, max = 100, value = 50),
dataTableOutput('my_table')
)
@msummersgill
msummersgill / gist:cfa44577c998f8988a3f02f07e4b9748
Last active May 10, 2017 15:22
group2NA_Benchmark_Option1
## Setup
```r
library(knitr)
knitr::opts_chunk$set(echo = TRUE)
## Installing dev versions of plotly with new data.table group2NA()
library(devtools)
library(withr)
library(ggplot2,lib.loc = "/home/Matthew14786/dev/")