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(timeseriesdb) # enthält Demo dataset | |
library(data.table) | |
library(tsbox) # time series toolbox von Christoph | |
# for better overview | |
tsl <- kof_ts[[20:70]] | |
dt <- tsbox::ts_dts(tsl) | |
dt_wide <- dcast(dt, time ~ id, value.var = "value") | |
fwrite(dt_wide, file = "triangle.csv") | |
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
rgb2hex <- function(r,g,b) sprintf('#%s',paste(as.hexmode(c(r,g,b)),collapse = '')) | |
rgb2hex(255,0,0) | |
# returns '#ff0000' |
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
# load packages - install from CRAN if you don't have the package: | |
# install.packages("waffle") | |
library(waffle) | |
# all data taken from | |
# basketball-reference.com - keep up the great work! | |
dubs <- c("X3p" = 251,"X2p" = 552 ,"FT" = 333) | |
dubs_points_scored <- dubs * c(3,2,1) | |
names(dubs_points_scored) <- c("by 3s","by 2s","by FTs") |
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 bash | |
# extend resources list and install R | |
sudo bash -c "echo 'deb http://stat.ethz.ch/CRAN/bin/linux/ubuntu trusty/' >> /etc/apt/sources.list" | |
sudo apt-get update | |
sudo apt-get install r-base | |
# install postgresql | |
sudo apt-get install postgresql |
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
dpl_gr <- function(ds,vars){ | |
ds %>% | |
group_by_(.dots = vars) %>% | |
summarise(n = n()) %>% | |
mutate(freq = n / sum(n)) | |
} | |
dpl_gr(mtcars,c("am","cyl")) |
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(MASS) | |
set.seed(123) | |
m <- mvrnorm(10000, mu = c(20,2.6), | |
Sigma = matrix(c(8,0.85,0.85,.57), | |
ncol = 2), | |
empirical = TRUE) | |
disp <- m[,1] | |
wt <- m[,2] | |
am <- rbinom(10000,1,.4) |
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
computeScores <- function(dframe, | |
maplist, | |
fct = sum, | |
na.rm = T){ | |
li <- lapply(maplist,function(x){ | |
out <- dframe[,grep(x,names(dframe),value=T)] | |
apply(out,1,fct, na.rm = na.rm) | |
}) |
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
# # convenience package... | |
# central vs. decentralized production discussion | |
# not part of this. | |
# minimal introduction to R | |
# different editors and an interpreter | |
# How-to-R Studio | |
# # 4 Panes | |
# # the ctrl+1 ctrl+2 shortcut | |
# # don't store |
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(openxlsx) | |
library(rvest) | |
journals <- read_html("https://www.aeaweb.org/econlit/journal_list.php") | |
j <- journals %>% | |
html_nodes(".journal") %>% | |
html_text() | |
dflist <- lapply(j,function(x){ |
NewerOlder