This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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: Alkalmazott statisztika? R! | |
author: Daróczi Gergely | |
date: 2016 | |
--- | |
Az R programozási nyelvvel és adatelemző, statisztikai és adatvizualizációs rendszerrel (R Core Team 2016) kicsit több mint 10 éve ismerkedtem meg felsőfokú tanulmányaim során, amikor is egy választható gazdaságszociológia kurzus keretén belül a magyarországi burgonyapiac kaotikus viselkedésével (Vizvári, Bacsi 1997; Vizvári 2002) volt szerencsém rövidebben foglalkozni. Ezt a személyes emléket azért tartottam fontosnak leírni, mert a káoszelmélettel való ismerkedés in medias res -- a kapcsolódó meglehetősen összetettnek tűnő matematikai háttér tárgyalása nélkül --, az alkalmazással indult, és az R-nek köszönhetően a félév végén sikerrel abszolváltam a kurzust. Ezzel párhuzamosan egy új és igen gazdag világ tárult fel előttem az R eszköztárával, amely évekkel később egyik legkedvesebb szabadidős elfoglaltságommá, majd elsődleges munkaeszközömmé vált. | |
Noha az R nyelv már több mint 20 éves múltra tekinthet vissza, népszerűségét legin |
This file contains hidden or 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
ddist <- function(df, quantiles = c(0,.02, .25, .50, .75, .90, .98, .99, .999, 1), na.rm = TRUE) { | |
numvars <- which(sapply(df, is.numeric)) | |
sapply(numvars, function(v) { | |
if (is.data.table(df)) { | |
v <- df[, v, with = FALSE] | |
} else { | |
v <- df[, v] | |
} | |
c(n = length(v), | |
ndistinct = length(unique(v)), |
This file contains hidden or 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 hidden or 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
-- create a new temp table with exact same schema | |
CREATE TABLE foobar_temp (LIKE foobar INCLUDING DEFAULTS); | |
-- or create this temp table with any new schema (eg updated col type) | |
CREATE TABLE foobar_temp (...) | |
-- copy everything from old table | |
INSERT INTO foobar_temp <list of columns> SELECT <list of columns> FROM foobar; | |
-- rename/drop tables |
This file contains hidden or 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
## fetch & parse data from Wikipedia | |
library(XML) | |
wiki <- 'https://en.wikipedia.org/wiki/Chronology_of_computation_of_%CF%80' | |
tables <- readHTMLTable(readLines(wiki), stringsAsFactors = FALSE) | |
## merge data from 4 tables | |
library(data.table) | |
pis <- rbindlist(list( | |
## data data before 1400 from 3rd table extracted by hand |
This file contains hidden or 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
## original idea & report by Henrik Bengtsson at | |
## https://stat.ethz.ch/pipermail/r-devel/2016-February/072388.html | |
## This script downloads the list of currently published R packages | |
## from CRAN and also looks at all the archived package versions to | |
## combine these into a list of all R packages ever published on | |
## CRAN with the date of first release. | |
## CRAN mirror to use | |
CRAN_page <- function(...) { |