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
rtime <- rpois(2000,1000) | |
rtime_mod <- c(rtime,rpois(20,200),rpois(40,10000)) | |
summary(rtime_mod) | |
quantile(rtime_mod,probs = seq(from = 0,1,by = .01) ) | |
ks.test(rexp(1000),rnorm(1000)) |
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 data from an SPSS file | |
library(foreign) | |
votematch<-read.spss("ioannis.sav", to.data.frame=TRUE, reencode="UTF-8") | |
# explore the loaded dataset | |
head(votematch) | |
dim(votematch) | |
names(votematch) | |
str(votematch) |
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 data, variables will be name X1 .... X8 | |
# dimension: 1200 rows, 7 cols | |
daten <- data.frame(matrix(rnorm(8400),ncol = 7)) | |
# 8th col is just sequential id 1-1200 | |
daten$id <- as.numeric(row.names(daten)) | |
# assume data are sorted, | |
# add another column that indicates | |
# the subset |
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
# getfame makes use of year from the tis package... | |
# and thus conflicts with data.table... if the fame package would import instead of | |
# depending on tis, everything would be solved... but it doesn't so this | |
# patch helps out. | |
# Hat tip to Richie cotton for helping me out in this SO thread | |
# http://stackoverflow.com/questions/26462903/how-to-handle-masking-conflicts-in-r-package-the-right-way | |
# The remaining problem with Richie's ideas was that getfame contains numerous not exported | |
# function so I had to hunt them down and add a fame:::functionname to it... | |
# here's the patch, TSget won't fail after loading data.table. YAY! | |
assignInNamespace( |
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
setMethod("dbIsValid", "PostgreSQLConnection", function(dbObj, ...) { | |
isValid <- tryCatch({dbGetInfo(dbObj)}, | |
error = function(e) NULL) | |
!is.null(isValid) | |
}) | |
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(RJSONIO) | |
library(RCurl) | |
fx <- getURL("http://www.quandl.com/api/v1/datasets/BOE/XUDLBK68") | |
fx_df <- data.frame(date = as.Date(unlist(lapply(fromJSON(fx)$data,"[[",1))), | |
EURCHF = unlist(lapply(fromJSON(fx)$data,"[[",2))) | |
# save("fx_df",file="presentation/data/fx_df_temp.RData") | |
plot(fx_df,main = "Swiss Franc per Euro Exchange Rate", | |
xlab = "Source: Quandl API (BOE)",ylab = "",type="l") | |
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
# just an implementation example that does not make a whole lot of sense... | |
library(MASS) | |
y <- mtcars$mpg | |
ll <- list(cars1 = mtcars[,-1], cars2 = mtcars[,-1]*100) | |
out_put_list <- lapply(ll,function(x){ | |
pca <- prcomp(x,scale.=T) | |
pca_scores <- as.data.frame(pca$x) | |
# maybe give back the result and do it | |
# multiple dfs |
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
library(fmsb) | |
# all data taken from basketball-reference.com | |
curry_now <- read.table(text="Season,Age,Tm,Lg,Pos,G,GS,MP,FG,FGA,FG%,3P,3PA,3P%,2P,2PA,2P%,eFG%,FT,FTA,FT%,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS | |
2015-16,27,GSW,NBA,PG,20,20,34.3,10.6,20.2,.524,5.1,11.1,.459,5.5,9.1,.602,.650,5.8,6.2,.943,0.5,4.6,5.1,6.0,2.4,0.2,3.6,1.7,32.0",sep=",",dec=".",header=T) | |
jordan_93 <- read.table(text="Season,Age,Tm,Lg,Pos,G,GS,MP,FG,FGA,FG%,3P,3PA,3P%,2P,2PA,2P%,eFG%,FT,FTA,FT%,ORB,DRB,TRB,AST,STL,BLK,TOV,PF,PTS | |
1992-93,29,CHI,NBA,SG,78,78,39.3,12.7,25.7,.495,1.0,2.9,.352,11.7,22.7,.514,.515,6.1,7.3,.837,1.7,5.0,6.7,5.5,2.8,0.8,2.7,2.4,32.6 | |
", | |
header = T,sep=",",dec=".") |