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
""" The task is to write comments (after ## ??) on every instance and describe it with the phrase is-a and has-a. | |
For further reference, please see ex41. """ | |
## Animal is-a object (yes, sort of cinfusing) look at the extra credit | |
class Animal(object): | |
pass | |
## ?? Class Dog is-a Animal that has-a __init__that takes self and name as parameters | |
class Dog(Animal): |
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
""" | |
Off the shelf way to skip already processed entities | |
This scripts processes files, remembers which files have been already | |
processed and skips them on the next run. | |
""" | |
import glob | |
import os | |
import shelve |
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
naloga <-data.frame("U308"=c(8.23, 8.78, 9.90, 10.90, 17.88, 29.00, 44.17, 83.01)) | |
naloga$Leto <- seq(from=2000, to=1999+length(naloga$U308)) | |
fit <- lm(log(U308) ~ Leto, data=naloga) | |
ggplot(naloga, aes(x = Leto, y = U308)) + | |
geom_point() + | |
ylab("Cena funta urana U308 v $") + | |
geom_function(fun = function(x) exp(coef(fit)[1]) * (exp(coef(fit)[2])^(x)), col="black", lty=2, size=0.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
library(adegenet) | |
data(H3N2) | |
dapc1 <- dapc(H3N2, pop=H3N2$other$epid, n.pca=30,n.da=6) | |
custom.cols <- rep(c("red", "blue"), times = c(1000,903)) | |
scatter(dapc1, col = custom.cols) |
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
# http://www.neilmclatchie.com/using-r-shading-area-under-a-distribution/ | |
stp <- 0.01 # "resolution" | |
left.limit <- -6 | |
right.limit <- 6 | |
plot( | |
x = NA, | |
type = "n", | |
lwd = 2, | |
lty = 1, |
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
# Use case: | |
# You have a weekly dataset and some variable for that week, i.e. | |
# week value year | |
# 1 528 2019 | |
# 2 503 2019 | |
# 3 493 2019 | |
# 4 487 2019 | |
# 5 526 2019 | |
# 6 523 2019 |
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
xy <- read.table(text = "date | lon | lat | trip | distancetocoast | |
2014-06-11 19:02:00 | -58,3508585 | -51,88438373 | 1 | 2236.067977 | |
2014-06-12 01:02:00 | -58,35589725 | -51,88349529 | 1 | 1000 | |
2014-06-12 13:02:00 | -58,27224941 | -51,91903677 | 1 | 7211,102551 | |
2014-06-12 19:02:00 | -58,27974654 | -51,90535003 | 1 | 5830,951895 | |
2014-06-13 01:02:00 | -58,32331901 | -51,89410464 | 1 | 3605,551275 | |
2014-06-13 07:02:00 | -58,35833139 | -51,88809227 | 1 | 1414,213562 | |
2014-06-13 13:02:00 | -58,35617673 | -51,88156281 | 1 | 1000 | |
2014-06-13 19:02:00 | -58,34055711 | -51,89002367 | 1 | 2236,067977 | |
2014-06-14 01:02:00 | -58,34982536 | -51,8715761 | 2 | 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
require(xts) | |
dailyip=readRDS(gzcon(url("https://dl.dropboxusercontent.com/s/kfxg1vi1s6hv6cg/dailyip.rds"))) | |
dailyrx=readRDS(gzcon(url("https://dl.dropboxusercontent.com/s/of47enf79ugkq8c/dailyrx.rds"))) | |
populate = function(x) { | |
if(unique(is.na(x))=='TRUE') return(x) | |
naseries=cbind(x,NA)[,2] | |
where=which(x<(yy))[1] | |
if(!is.na(where)) return(na.locf(cbind(x[1:where],naseries)[,1])) |
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(raster) | |
library(microbenchmark) | |
logo <- stack(system.file("external/rlogo.grd", package="raster")) | |
la <- as.array(logo) | |
microbenchmark(vanilla = mean(logo), | |
overlay = overlay(logo, fun = mean), times = 50, calc(logo, fun = mean), | |
rasterapply = {raster(apply(la, MARGIN = c(1,2), FUN = mean))}, | |
norasterapply = {apply(la, MARGIN = c(1,2), FUN = mean)}) |
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(scrbook) | |
scrPID.um2 <- function (n, X, y, M, mmax, obsmod = c("pois", "bern"), niters, | |
npics, xlims, ylims, inits, delta) | |
{ | |
obsmod <- match.arg(obsmod) | |
J <- nrow(n) | |
K <- ncol(n) | |
S <- inits$S | |
D <- e2dist(S, X) |
NewerOlder