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
## ############################################################################# | |
## PCA demo on image processing | |
## ############################################################################# | |
download.file('http://bit.ly/nasa-image-pca', 'image.jpg') # mode = »bw« | |
library(jpeg) | |
img <- readJPEG('image.jpg') | |
str(img) |
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
#!/usr/bin/env python | |
import dbus, dbus.exceptions | |
import sys | |
import re | |
try: | |
bus = dbus.SessionBus() | |
timetracker = bus.get_object('org.gnome.Shell', '/timepp/zagortenay333/TimeTracker') | |
except dbus.exceptions.DBusException as e: |
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
## ############################################################################# | |
## intro slides: http://bit.ly/CRUNCH-R-2018 | |
## ############################################################################# | |
## intro to R | |
## basic operations | |
1 + 3 | |
3 * 2 |
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
## generate transactional tables | |
set.seed(42) | |
library(data.table) | |
tx <- data.table( | |
item = sample(letters[1:3], 10, replace = TRUE), | |
time = as.POSIXct(as.Date('2016-01-01')) - runif(10) * 36*60^2, | |
amount = rpois(10, 25)) | |
prices <- data.table( | |
item = letters[1:3], | |
date = as.Date('2016-01-01') - 1:2, |
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
m1 <- lm(mpg ~ hp, data = mtcars) | |
m2 <- lm(mpg ~ hp + drat, data = mtcars) | |
m3 <- lm(mpg ~ hp + drat + factor(gear), data = mtcars) | |
library(pander); library(memisc) | |
panderOptions('table.alignment.rownames', 'left') | |
pander(relabel( | |
mtable(m1, m2, m3, | |
summary.stats=c('N', 'R-squared', 'F')), | |
'(Intercept)' = 'Constant', |
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(XML) | |
html <- htmlParse(readLines('https://www.meetup.com/topics/r-project-for-statistical-computing/all/')) | |
names <- xpathSApply(html, '//li[@class="gridList-item"]/a/span', xmlValue) | |
attrs <- xpathSApply(html, '//li[@class="gridList-item"]/span[@class="text--secondary text--small chunk"]', xmlValue) | |
attrs <- gsub('\\n|\\t', '', attrs) | |
users <- as.numeric(gsub(',', '', sub('^([0-9,]*) .*', '\\1', attrs))) | |
geo <- sub('.* \\| ', '', attrs) | |
data.frame(name = names, location, members) |
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
## intro slides: http://bit.ly/r-intro-slide | |
## basic operations | |
1 + 3 | |
3*2 | |
3^2 | |
## constants | |
pi | |
"pi" |
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
## intro slides: http://bit.ly/CRUNCH-R-2017 | |
## basic operations | |
1 + 3 | |
3*2 | |
3^2 | |
## constants | |
pi | |
"pi" |
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
# demo transactions data | |
library(data.table) | |
txns <- data.table( | |
rpid = rep(1:3, times = 4), | |
txid = 1:12, | |
time = c(10, 10, 10, 11, 15, 20, 12, 16, 25, 13, 21, 30)) | |
## overlap join to see which transactions happened withing 3 time units on the same rpid | |
## let's define the time periods for the overlap | |
txns[, start := time - 3] |
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
#' Connect and query Imapala via SSH and Impala-shell | |
#' @param query SQL query to run | |
#' @param host server hostname or IP | |
#' @param log enable or disable logging of debug/trace messages | |
#' @return data.table object | |
#' @export | |
query_impala <- function(query, host = 'localhost', log = require(futile.logger)) { | |
## measure time of query | |
timer <- proc.time() |