Skip to content

Instantly share code, notes, and snippets.

View BroVic's full-sized avatar
🎯
Focusing

Victor Ordu BroVic

🎯
Focusing
View GitHub Profile
@BroVic
BroVic / create-list.R
Last active September 6, 2019 12:11
Quick exercise to introduce R atomic vectors
#####################
# #
# Lists #
# #
#####################
# Note that the function arguments used in this sample script are rather verbose
# just to enhance your understanding. You DO NOT always need to specify arguments.
## We MAY first of all create components:
@BroVic
BroVic / why-glue.R
Created March 16, 2020 12:45
Why would I want to use glue instead of base functions for string interpolation?
# Why 'glue' and not 'paste' or 'sprintf'
# adapting the example
library(microbenchmark)
library(glue)
name <- "Fred"
age <- 30
anniversary <- as.Date('1991-10-12')
@BroVic
BroVic / Makefile
Last active March 18, 2020 13:57
A Makefile for cleaning and transforming data, generating HTML codebooks and building MS Word reports
## -- Makefile -- ##
##
## MIT License
##
## Copyright (c) 2019 Victor Ordu
##
## -------------- ##
ROOTDIR = ./
DWNDIR = $(ROOTDIR)downloads/
@BroVic
BroVic / covid-ecdc.R
Last active April 22, 2020 23:26
A simple R script for displaying daily COVID-19 reporting by countries
# Inspired by https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide
# System requirements: Recent version of R e.g. R-3.6.x (www.r-project.org)
#
# Running the script:
# 1. From the command line: Navigate to directory where script is saved and
# there run this command:
# Rscript covid-ecdc.R
#
# 2. From the R console: Call the `source()` function using the relative or
# titanic.R
## An R Script on simple exploration of the Titanic dataset
## In RGui, to run an R script's line hold CTRL + R
## Download the dataset into the working directory
# Check the working directory,
getwd()
@BroVic
BroVic / adapt_eventBrite.R
Last active May 18, 2020 20:06
Trimming EventBrite data to suit local purpose
library(here)
suppressPackageStartupMessages(library(dplyr))
ourDir <- file.path(here(), "events/StatesmanSeries/data")
ebriteCsv <- file.path(ourDir, "SOGP_Eventbrite Reg.csv")
eBrite <- read.csv(ebriteCsv, stringsAsFactors = FALSE)
vars <- colnames(eBrite)
dat <- eBrite %>%
@BroVic
BroVic / comp-check1.R
Last active May 19, 2020 18:30
Harvard PH125.8x: Section 2
# comp-check1.R
library(tidyverse)
library(MASS)
library(caret)
set.seed(1)
Sigma <- 9 * matrix(c(1, 0.5, 0.5, 1), 2, 2)
dat <- mvrnorm(n = 100, c(69, 69), Sigma = Sigma) %>%
data.frame() %>%
@BroVic
BroVic / install-pssqlite.ps1
Created June 19, 2020 15:22
A PowerShell script for installing the PSSQLite Module
# install-pssqlite.ps1
# Copyright (c) 2018 Victor Ordu. All rights reserved.
# See LICENSE for details.
Write-Verbose "Checking for avaiablity of PSSQLite Module"
# Check if SQLite is (properly) installed
if(-not $ENV:Path.Contains('sqlite')) {
Write-Error "'sqlite3' does not exist or is not on system PATH."
@BroVic
BroVic / client.R
Last active August 11, 2020 01:34
Implementing client-server connection in R
# Socket connections
# Client side
# http://blog.corynissen.com/2013/05/using-r-to-communicate-via-socket.html
client <- function(){
while (TRUE) {
con <- socketConnection(host = "localhost", port = 6011, blocking = TRUE,
server = FALSE, open = "r+")
f <- file("stdin")
open(f)
library(dslabs)
library(dplyr)
library(lubridate)
library(caret)
data("reported_heights")
dat <-
mutate(reported_heights, date_time = ymd_hms(time_stamp)) %>%
filter(date_time >= make_date(2016, 01, 25) &