Skip to content

Instantly share code, notes, and snippets.

# get the FX rates from Quandl
gbppln <- Quandl("CURRFX/GBPPLN")
# xts object for dygraphs
gbppln_xts <- Quandl("CURRFX/GBPPLN", type="xts")
# stl expects a time series data type
gbppln_ts <- Quandl("CURRFX/GBPPLN",
collapse="monthly",
type="ts")
# change column names to R-friendly format
colnames(gbppln)[colnames(gbppln)=="High (est)"] <- "High_est"
colnames(gbppln)[colnames(gbppln)=="Low (est)"] <- "Low_est"
# change column names to R-friendly format
colnames(gbppln_xts)[colnames(gbppln_xts)=="High (est)"] <- "High_est"
colnames(gbppln_xts)[colnames(gbppln_xts)=="Low (est)"] <- "Low_est"
# remove the high/low estimates columns
gbppln_xts$High_est <- NULL
# Reuters-like colours
# https://s3.amazonaws.com/quandl-static-content/Documents/Quandl+-+R+Cheat+Sheet.pdf
fx.plot <- ggplot(data = gbppln, aes(x=Date,y=Rate)) +
geom_line(color = "#FAB521")+
theme(panel.background = element_rect(fill="#393939"),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(colour="white", size=0.1),
panel.grid.minor = element_line(colour="white", size=0.1)) +
xlab("Date") +
ylab("GBP/PLN") +
library(AnomalyDetection)
library(dygraphs)
library(ggplot2)
library(lubridate)
library(magrittr)
library(Quandl)
# run the anomaly detection
posixDate <- as.POSIXct(gbppln$Date)
gbppl_ad_df <- data.frame(posixDate, gbppln$Rate)
fx.ad <- AnomalyDetectionVec(gbppl_ad_df$gbppln.Rate,
max_anoms=0.05,
direction='both',
plot=TRUE,
period=30)
# plot the anomalies
@erzk
erzk / gtrends_ngramr.R
Created November 21, 2015 20:12
Query Google Trends and Google Ngrams using R
# install necessary packages
devtools::install_github("dvanclev/GTrendsR")
devtools::install_github("trinker/gtrend")
# load the packages
library(curl)
library(dplyr)
library(gtrend)
library(ggplot2)
library(ngramr)
# analyse data about 2015 Polish parliamentary elections
# more info: http://smarterpoland.pl/index.php/2015/12/czy-internet-pozwala-przewidziec-wyniki-wyborow/
library(Amelia)
library(ggplot2)
library(tabplot)
# load the data
dane <- read.table("https://raw.githubusercontent.com/pbiecek/SmarterPoland_blog/master/dane/Wybory2015/2r.txt",
header=T,
sep="\t",
@erzk
erzk / read-file-praat.txt
Created January 9, 2016 18:42
header to add to txt files that will enable opening them using Praat
File type = "ooTextFile"
Object class = "Sound 2"
0
0.41
6536
0.0000610221205187
0.0000305110602593
1
1
@erzk
erzk / txt2praat.R
Last active January 9, 2016 18:59
append txt with a short text format to enable reading txt file in praat
txt2praat <- function(x, filename) {
# Appends the Praat header to enable txt vector to be read in Praat.
#
# Args:
# x: A path to the txt file (vector) that the header attached will be attached to.
# Example:
# >x <- file.choose()
#
# filename: Optional argument specifying the output file name
#
@erzk
erzk / Map_of_countries_in_top_100_CWUR.R
Created March 20, 2016 12:25
Kaggle dataset analysis - World University Rankings
# countries by the number of universities in the CWUR ranking
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(rworldmap)
cwur <- read.csv("cwurData.csv")
# data frames with the universities and count them by country